Memory allocation macros

Bob Friesenhahn <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.core
Message-ID <[email protected]>
GraphicsMagick CVS has now been updated to use two of the three memory
allocation macros which were proposed.  The macros currently in use
are MagickFreeMemory and MagickReallocMemory.  Whereas the previous
memory allocation functions require a pointer cast to type (void **),
these macros manage to accomplish the task without a cast.  I have
tested compilation using Visual C++, GCC 3.3, and the proprietary
compilers from Sun, HP, and IBM's AIX and they all swallowed the
macros ok.  I can't say if the latter three compilers might have
produced new warnings at a higher warning level since I used default
compilation options.

It was necessary to test on quite a few compilers since if a compiler
doesn't accept the macro code without a cast, there are several spots
where it would be impossible to add a cast without adding another
macro argument.  Luckily, it seems that the technique used is
surviving many compilers, so it is likely to work with all modern
C compilers.

The advantage of the macros over the functions are:

  o no cast required (casts tend to hide bugs)
  o the macros invoke malloc, free, and realloc directly from the
    function which uses them, which produces better reports from
    memory leak checkers.
  o The macros avoid some new warnings which appeared in GCC 3.3.

Quite a few minor issues were detected and corrected while updating
the code to use the macros.  For example, there were many cases where
const values were being freed.

Bob
======================================
Bob Friesenhahn
[email protected]
http://www.simplesystems.org/users/bfriesen



-------------------------------------------------------
This SF.net email is sponsored by: If flattening out C++ or Java
code to make your application fit in a relational database is painful, 
don't do it! Check out ObjectStore. Now part of Progress Software.
http://www.objectstore.net/sourceforge
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.