Page 1 of 1

writeImages() uses a LOT of memory

Posted: 2010-08-28T11:30:27-07:00
by anotherprogrammer123
Hi,

I am storing images in my own image format and converting them to magick++ for file/save operations.
When I use writeImages() on lets say 7 images, I have to store 7 times as much pixel data in memory into a STL container in order to call writeImages(). Even though magick++ is reference counted, it can't share with my image data right?

Code: Select all

//Loop through myImages (a vector<myImage>) and convert all to a magick++ and store in vector
vector<Image> magickImages = ConvertToMagicks(myImages);
writeImages(magickImages.begin(), magickImages.end(), "c:/image.tif"); //so much memory being used here
Is there any way I can reduce memory usage? Perhaps there is a smart container that can de-allocate each image as it is accessed by magick++?

Re: writeImages() uses a LOT of memory

Posted: 2010-08-28T12:18:52-07:00
by magick
You can set resource limits to force all image pixels to disk. Its slower but it trades off memory for disk resource usage. For a quick test, set the MAGICK_AREA_LIMIT environment variable to 0 (see http://www.imagemagick.org/script/resou ... nvironment) then run your program.

Re: writeImages() uses a LOT of memory

Posted: 2010-08-28T13:00:35-07:00
by anotherprogrammer123
Thanks, that works. But it costs a lot of efficiency, which is kind of important for my case.

I meant above that Magick++ should only need access to 1 image at a time, right? So, is there some container I can use that frees memory as each elements is accessed? Or, would this mess up writeImages()?

Re: writeImages() uses a LOT of memory

Posted: 2010-08-28T13:06:52-07:00
by magick
is there some container I can use that frees memory as each elements is accessed?
No. That is why the resource limits work. Effectively only the image container is in memory and the pixel cache is on disk.

Re: writeImages() uses a LOT of memory

Posted: 2010-08-28T14:16:05-07:00
by anotherprogrammer123
:( that's kind of disappointing, but thanks again for the response!