Question
Memory allocation failure
Hello all,
I am writing a Windows plug-in, 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 the 'FilterRecord->bufferProcs->allocateProc' procedure. 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 will fail, 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 (my computer has 2 GB), so what is going on? I could maybe understand that Photoshop 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
I am writing a Windows plug-in, 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 the 'FilterRecord->bufferProcs->allocateProc' procedure. 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 will fail, 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 (my computer has 2 GB), so what is going on? I could maybe understand that Photoshop 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
