Memory allocation failure

Discussion in 'C Programming' started by vectorizor, May 22, 2007.

  1. vectorizor

    vectorizor Guest

    Hello all,

    I am writing a Photoshop plug-in on Windows, and I am having trouble
    with allocating memory. Essentially, the code performs a very complex
    operation on the image, so 9 buffer planes are required as scratch
    memory. The problem occurs when the image that a user tries to process
    is big, say 10 mega pixels or more. A Photoshop error pops up saying
    "Could not complete the command because of a program error".

    The error occurs in Photoshop's memory allocation routine,
    'FilterRecord->bufferProcs->allocateProc'. It simply fails, hence the
    problem must be allocating the memory. So I tried to replace this with
    a call to a good old malloc, but trying to allocate the 9 planes
    fails, because malloc returns a NULL pointer.

    Now the weird thing is that processing a single 10MB will fail,
    whereas I can process seven or eight 8MB images without a complaint
    from Photoshop. Furthermore, with those seven or eight 8MB still open
    in Photoshop, I can process a 20MB image with a command-line
    equivalent of the plug-in. So in a nutshell, there is enough memory
    as I can allocated twice more memory than what fails in Photoshop, so
    what is going on? I could maybe understand that the Photoshop function
    refuses to allocate such memory for some reasons, but why does the
    malloc in the plug-in fail?! Especially since the malloc in the
    command-line equivalent succeeds without a problem for an image TWICE
    bigger?!

    I would greatly appreciate any comments/ideas/suggestions.

    Thanks in advance

    Alex
    vectorizor, May 22, 2007
    #1
    1. Advertising

  2. On 22 May 2007 01:49:08 -0700, vectorizor <>
    wrote:

    >Hello all,
    >


    snip Photoshop discussion

    >
    >Now the weird thing is that processing a single 10MB will fail,
    >whereas I can process seven or eight 8MB images without a complaint
    >from Photoshop. Furthermore, with those seven or eight 8MB still open


    The fact that "small" allocations succeed while a "large" fails may
    indicate nothing more sinister that memory fragmentation. (How many
    pieces of kindling will fit through your front door vs how many full
    grown redwoods?)

    >in Photoshop, I can process a 20MB image with a command-line
    >equivalent of the plug-in. So in a nutshell, there is enough memory
    >as I can allocated twice more memory than what fails in Photoshop, so
    >what is going on? I could maybe understand that the Photoshop function


    This would seem to indicate that when Photoshop is active it does
    something "strange" to the virtual memory in that task. As with most
    virtual memory systems, each task has its own memory and whatever
    Photoshop did with its is not affecting your command line task.

    >refuses to allocate such memory for some reasons, but why does the
    >malloc in the plug-in fail?! Especially since the malloc in the
    >command-line equivalent succeeds without a problem for an image TWICE
    >bigger?!
    >
    >I would greatly appreciate any comments/ideas/suggestions.


    You really need to discuss this in a Photoshop newsgroup. You have
    demonstrated that the problem is not likely in your C code or the C
    run time library. Does Adobe provide any kind of tech support?

    An alternative design, obviously slower but available immediately, is
    to use files instead of allocated memory.


    Remove del for email
    Barry Schwarz, May 22, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Koen
    Replies:
    1
    Views:
    938
    Michiel Salters
    Jun 25, 2003
  2. Ken
    Replies:
    24
    Views:
    3,856
    Ben Bacarisse
    Nov 30, 2006
  3. chris
    Replies:
    6
    Views:
    985
    chris
    Oct 28, 2005
  4. Saeed Amrollahi
    Replies:
    10
    Views:
    690
    Kevin P. Fleming
    Jan 8, 2011
  5. Bjarke Hammersholt Roune
    Replies:
    14
    Views:
    1,180
    Bjarke Hammersholt Roune
    Mar 6, 2011
Loading...

Share This Page