2010年5月3日 星期一

Garbage Collection in GraphicsMagick

Using GraphicsMagick, when you want to rotate, scale, normalize... or doing anything to the image.




/* A line to fill table x-axis in html A line to fill table x-axis in html A line to fill table x-axis in html*/
InitializeMagick(argv[0]);
ImageInfo *info=new ImageInfo;
ExceptionInfo * excp=new ExceptionInfo;

GetImageInfo(info);
GetExceptionInfo(excp);
strcpy(info->filename,argv[1]);
Image * ii = ReadImage(info,excp);

ii=RotateImage(ii,270,excp);
/* The original ii is lost!!! */

Using a tmp variable




/* A line to fill table x-axis in html A line to fill table x-axis in html A line to fill table x-axis in html*/
Image * tmp = RotateImage(ii,270,excp);
DestroyImage(ii);
ii=tmp;
/* To much trouble... */

Using Boehm Garbage Collector


/* A line to fill table x-axis in html A line to fill table x-axis in html A line to fill table x-axis in html*/
#define GC_DEBUG
#include <gc/gc.h>
#define CHECK_LEAKS() GC_gcollect()

GC_init();
/*for GM*/
MagickAllocFunctions(GC_free,GC_malloc,GC_realloc);
/*for IM*/
SetMagickMemoryMethods(\
(AcquireMemoryHandler)GC_malloc,\
(ResizeMemoryHandler)GC_realloc,\
(DestroyMemoryHandler)GC_free);
        
/* Set Memory Alloc/Dealloc function to GC before calling any IM/GM function */
InitializeMagick(argv[0]);

/* Call GC anytime you like */
CHECK_LEAKS();


沒有留言:

張貼留言