Main Page   Modules   Alphabetical List   Compound List   Compound Members  

Memory Management Utilities


Functions

void cpl_memory_init (void)
 Initialise the memory management subsystem. More...

void * cpl_malloc (size_t nbytes)
 Allocate nbytes bytes. More...

void * cpl_malloc_clear (size_t nbytes)
 Allocate nbytes bytes and clear them. More...

void * cpl_calloc (size_t natoms, size_t nbytes)
 Allocate memory for natoms elements of size size. More...

void * cpl_realloc (void *memblk, size_t nbytes)
 Change the size of a memory block. More...

void cpl_free (void *memblk)
 Memory block deallocation. More...


Detailed Description

This module provides the CPL memory management utilities. CPL uses its own memory management system in order to provide almost infinite virtual memory (only limited by the file system size). However, this functionality has certain restrictions. Memory which was allocated using one of the CPL allocator functions must be released with the CPL deallocator function. The same applies to memory blocks allocated and returned by CPL functions. The CPL memory management subsystem uses the services provided by qfits' xmemory module.

Function Documentation

void* cpl_calloc size_t    natoms,
size_t    nbytes
 

Allocate memory for natoms elements of size size.

Parameters:
natoms  Number of atomic elements.
nbytes  Element size in bytes.
Returns:
Pointer to the allocated memory block.
The function allocates memory suitable for storage of natoms elements of size nbytes bytes. The allocated memory is cleared, i.e. the value 0 is written to each single byte.

Note:
If the memory subsytem has not been initialised before calling this function, the program execution is stopped printing a message to the error channel showing the current code position.

void cpl_free void *    memblk
 

Memory block deallocation.

Returns:
Nothing.
Deallocates a memory block previously allocated by any of the CPL allocator functions.

See also:
cpl_malloc(), cpl_malloc_clear(), cpl_calloc()

void* cpl_malloc size_t    nbytes
 

Allocate nbytes bytes.

Parameters:
nbytes  Number of bytes.
Returns:
Pointer to the allocated memory block.
The function allocates nbytes bytes of memory. The allocated memory is not cleared.

Note:
If the memory subsytem has not been initialised before calling this function, the program execution is stopped printing a message to the error channel showing the current code position.
See also:
cpl_malloc_clear()

void* cpl_malloc_clear size_t    nbytes
 

Allocate nbytes bytes and clear them.

Parameters:
nbytes  Number of bytes.
Returns:
Pointer to the allocated memory block.
The function works as cpl_malloc(), but the allocated memory is cleared, i.e. a 0 is written to each byte of the allocated block.

See also:
cpl_malloc()

void cpl_memory_init void   
 

Initialise the memory management subsystem.

Returns:
Nothing.
The function initialises the CPL memory management subsystem, i.e. it redirects any request for allocating or deallocating memory to the xmemory module of qfits.

This must be called, once and only once, before any memory is allocated, either by calling any of the allocator functions directly, or indirecly by calling a CPL function which allocates memory.

Note:
Usually, there is no need to call this function directly, since it is automatically called by the library initialisation function cpl_init().
See also:
cpl_init()

void* cpl_realloc void *    memblk,
size_t    nbytes
 

Change the size of a memory block.

Parameters:
memblk  Number of atomic elements.
nbytes  New memory block size in bytes.
Returns:
Pointer to the allocated memory block.
The function changes the size of an already allocated memory block memblk to the new size nbytes bytes. The contents is unchanged to the minimum of old and new size; newly allocated memory is not initialized. If memblk is NULL the call to cpl_realloc() is equivalent to cpl_malloc(), and if nbytes is 0 the call is equivalent to cpl_free(). Unless memblk is NULL, it must have been returned by a previous call to cpl_malloc(), cpl_malloc_clear(), cpl_calloc(), or cpl_realloc().

Note:
  • The returned memory block returned on successfull allocation may not be the same as the one pointed to by memblk. Existing references pointing to locations within the original memory block might be invalidated!
  • If the memory subsytem has not been initialised before calling this function, the program execution is stopped printing a message to the error channel showing the current code position.
See also:
cpl_malloc(), cpl_malloc_clear(), cpl_calloc()


Generated on Mon May 24 14:58:05 2004 for Common Pipeline Library Reference Manual by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002