POSIX-compatible extended memory handling


Functions

void * cpl_xmemory_calloc (size_t nmemb, size_t size)
 Allocate memory.
void * cpl_xmemory_calloc_count (size_t nmemb, size_t size)
 calloc() with failure check
void cpl_xmemory_free (void *ptr)
 Free memory.
void cpl_xmemory_free_count (void *ptr)
 Free memory.
int cpl_xmemory_is_empty (int mode)
 Tell if there is still some memory allocated.
void * cpl_xmemory_malloc (size_t size)
 Allocate memory.
void * cpl_xmemory_malloc_count (size_t size)
 malloc() with failure check
void * cpl_xmemory_realloc (void *oldptr, size_t size)
 Re-Allocate memory.
void * cpl_xmemory_realloc_count (void *oldptr, size_t size)
 realloc() with failure check
void cpl_xmemory_status (int mode)
 Display memory status information.

Detailed Description

cpl_xmemory is a small and efficient module offering memory extension capabitilies to ANSI C programs running on POSIX-compliant systems. It offers several useful features such as memory leak detection, protection for free on NULL or unallocated pointers. This module has been tested on a number of current Unix * flavours and is reported to work fine. The current limitation is the limited number of pointers it can handle at the same time.

Function Documentation

void* cpl_xmemory_calloc ( size_t  nmemb,
size_t  size 
)

Allocate memory.

Parameters:
nmemb Number of elements to allocate.
size Size (in bytes) of each element.
Returns:
1 newly allocated pointer.

void* cpl_xmemory_calloc_count ( size_t  nmemb,
size_t  size 
)

calloc() with failure check

Parameters:
nmemb Number of elements to allocate.
size Size (in bytes) to allocate.
Returns:
1 newly allocated pointer (possibly NULL on zero bytes)
Note:
Will abort() on failure

void cpl_xmemory_free ( void *  ptr  ) 

Free memory.

Parameters:
ptr Pointer to free.
Returns:
void
Note:
Nothing is done on NULL
See also:
free()
Free the memory associated to a given pointer. Prints a warning on stderr if the requested pointer cannot be found in the memory table. If the pointer ptr is NULL, nothing is done and no error is set.

void cpl_xmemory_free_count ( void *  ptr  ) 

Free memory.

Parameters:
ptr Pointer to free.
Returns:
void
See also:
free()

int cpl_xmemory_is_empty ( int  mode  ) 

Tell if there is still some memory allocated.

Parameters:
mode Mode (0: system, 1: Xmemory-failure check, 2: Xmemory-full)
Returns:
1 if the memory table is empty, 0 if no, -1 if the memory model is off

void* cpl_xmemory_malloc ( size_t  size  ) 

Allocate memory.

Parameters:
size Size (in bytes) to allocate.
Returns:
1 newly allocated pointer.
This function is a replacement call for malloc. It should never be called directly but through a macro instead, as:

void* cpl_xmemory_malloc_count ( size_t  size  ) 

malloc() with failure check

Parameters:
size Size (in bytes) to allocate.
Returns:
1 newly allocated pointer (possibly NULL on zero bytes)
Note:
Will abort() on failure

void* cpl_xmemory_realloc ( void *  oldptr,
size_t  size 
)

Re-Allocate memory.

Parameters:
oldptr Pointer to free.
size Size (in bytes) to allocate.
Returns:
1 newly allocated pointer.

void* cpl_xmemory_realloc_count ( void *  oldptr,
size_t  size 
)

realloc() with failure check

Parameters:
oldptr Pointer to reallocate.
size Size (in bytes) to reallocate.
Returns:
1 newly allocated pointer (possibly NULL on zero bytes)
Note:
Will abort() on failure

void cpl_xmemory_status ( int  mode  ) 

Display memory status information.

Parameters:
mode Mode (0: system, 1: Xmemory-failure check, 2: Xmemory-full)
Returns:
void
This function is meant for debugging purposes, but it is recommended to call it at the end of every executable making use of the extended memory features.


Generated on Wed Mar 18 09:40:13 2009 for Common Pipeline Library Reference Manual by  doxygen 1.4.7