NAME
kjb_realloc - Reallocates memory from the heap.
SYNOPSIS
#include "l/l_sys_mal.h"
Example compile flags (system dependent):
-DLINUX_X86_64 -DLINUX_X86_64_OPTERON -DGNU_COMPILER
-I/home/kobus/include
-L/home/kobus/misc/load/linux_x86_64_opteron -L/usr/lib/x86_64-linux-gnu
-lKJB -lfftw3 -lgsl -lgslcblas -ljpeg -lSVM -lstdc++ -lpthread -lSLATEC -lg2c -lacml -lacml_mv -lblas -lg2c -lncursesw
void *kjb_realloc
(
void *ptr,
Malloc_size num_bytes
);
DESCRIPTION
This routine is a replacement for realloc. It provides some error checking in
the case of development code (compiled with -DTEST), some platform
independence with respect to remalloc's behaviour, and error reporting
consistent with the KJB library.
If TRACK_MEMORY_ALLOCATION is defined (on unix, this is normally defined if
TEST is #defined) then this routine is #define'd to be debug_kjb_realloc,
which is the version available in the development library. In development
code, memory is tracked so that memory leaks can be found more easily.
Furthermore, all memory free'd is checked that it was allocated by a KJB
library routine, and that it has not already been freed (this is a common
source of nasty bugs). Finally, memory is checked for overruns. Most of these
problems are spotted when the code calls kjb_free. If a problem is spotted,
then you are notified, and asked if you want to abort. If you then abort,
then you simply need to go up a few stack frames with the debugger to find ut
where you were free'ing something that you should not be, or what was freed
that was over-run. The memory leak check is simply a report supplied at
program exit of the memory not freed, and where it was allocated. Since it is
often more useful that the allocation location is specified with respect
to higher level operations (such as creating a matrix), some routines such as
create_matrix will set it up so that the location reported is the matrix
creation call, not the call to kjb_realloc.
The routine kjb_free should be used to free memory allocated by this routine.
kjb_free is normally accessed through the macro kjb_free.
RETURNS
On error, this routine returns NULL, with an error message being set.
On success it returns a pointer to the memory, just like malloc.
MACROS
Normally kjb_realloc should be accessed through macros to provide the
casts. The available macros are:
KJB_REALLOC(x), TYPE_REALLOC(t), N_TYPE_REALLOC(t,n), VOID_REALLOC(x),
UCHAR_REALLOC(x), BYTE_REALLOC(x), STR_REALLOC(x), SHORT_REALLOC(x),
INT_REALLOC(x), LONG_REALLOC(x), FLT_REALLOC(x), DBL_REALLOC(x),
INT16_REALLOC(x), UINT16_REALLOC(x), INT32_REALLOC(x), UINT32_REALLOC(x),
DBL_REALLOC(x)
The use of these is relatively obvious, except possibly N_TYPE_REALLOC,
which takes a type name as the first argument, and the number that you
want as the second.
DISCLAIMER
This software is not adequatedly tested. It is recomended that
results are checked independantly where appropriate.
AUTHOR
Kobus Barnard
DOCUMENTER
Kobus Barnard
SEE ALSO
memory_used
,
kjb_malloc
,
kjb_calloc
,
watch_for_free
,
check_initialization
,
optimize_free
,
optimize_free_2
,
kjb_free