writeImages() uses a LOT of memory

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
anotherprogrammer123
Posts: 36
Joined: 2010-02-21T18:02:40-07:00
Authentication code: 8675308

writeImages() uses a LOT of memory

Post 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++?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: writeImages() uses a LOT of memory

Post 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.
anotherprogrammer123
Posts: 36
Joined: 2010-02-21T18:02:40-07:00
Authentication code: 8675308

Re: writeImages() uses a LOT of memory

Post 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()?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: writeImages() uses a LOT of memory

Post 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.
anotherprogrammer123
Posts: 36
Joined: 2010-02-21T18:02:40-07:00
Authentication code: 8675308

Re: writeImages() uses a LOT of memory

Post by anotherprogrammer123 »

:( that's kind of disappointing, but thanks again for the response!
Post Reply