Libg++ contains versions of
malloc, free, realloc that were
designed to be well-tuned to C++ applications. The source file
`malloc.c' contains some design and implementation details.
Here are the major user-visible differences from most system
delete'd object in any way. Doing so will either result in trapped fatal errors or random aborts within malloc, free, or realloc.
operator new()to call malloc and
operator delete()to call free. Of course, you may override these definitions in C++ programs by creating your own operators that will take precedence over the library versions. However, if you do so, be sure to define both
reallocwith a pointer that has been
free'd pointers that can often determine whether users have accidentally written beyond the boundaries of allocated space, resulting in a fatal error.
malloc_usable_size(void* p)returns the number of bytes actually allocated for
p. For a valid pointer (i.e., one that has been
realloc'd but not yet
free'd) this will return a number greater than or equal to the requested size, else it will normally return 0. Unfortunately, a non-zero return can not be an absolutely perfect indication of lack of error. If a chunk has been
free'd but then re-allocated for a different purpose somewhere elsewhere, then
malloc_usable_sizewill return non-zero. Despite this, the function can be very valuable for performing run-time consistency checks.
mallocrequires 8 bytes of overhead per allocated chunk, plus a mmaximum alignment adjustment of 8 bytes. The number of bytes of usable space is exactly as requested, rounded to the nearest 8 byte boundary.
Go to the first, previous, next, last section, table of contents.