Barracuda Application Server C/C++ Reference
NO
|
Memory allocation and deallocation Interface class.
This abstract interface class is used by some of the Barracuda classes when allocating memory. The reason for using an interface class and not directly calling the global functions baMalloc(), baRealloc() and baFree() is to provide a finer control of allocated memory. For example, an implementation of the AllocatorIntf can work with blocks of memory allocated from static memory. Implementing realloc is optional and can be set to NULL if not implemented.
#include <AllocatorIntf.h>
Public Member Functions | |
AllocatorIntf (AllocatorIntf_Malloc malloc, AllocatorIntf_Realloc realloc, AllocatorIntf_Free free) | |
Create an instance of a memory allocation class. More... | |
void * | malloc (size_t *size) |
Returns pointer to uninitialized newly-allocated space for an object of size "size", or NULL on error. More... | |
void * | realloc (void *p, size_t *size) |
Returns pointer to newly-allocated space for an object of size "size", initialized, to minimum of old and new sizes, to existing contents of p (if non-null), or NULL on error. More... | |
void | free (void *p) |
Deallocates space to which it points. | |
Static Public Member Functions | |
static AllocatorIntf * | getDefault (void) |
Returns a pointer to a predefined AllocatorIntf class. More... | |
AllocatorIntf::AllocatorIntf | ( | AllocatorIntf_Malloc | malloc, |
AllocatorIntf_Realloc | realloc, | ||
AllocatorIntf_Free | free | ||
) |
Create an instance of a memory allocation class.
This is an abstract base class and should, therefore, be sub-classed.
malloc | Pointer to memory allocation method. |
realloc | Pointer to memory reallocation method. This method is optional and the argument can be set to NULL if not implemented. |
free | Pointer to a memory deallocation method. |
|
static |
Returns a pointer to a predefined AllocatorIntf class.
The default implementation uses method baMalloc(), baRealloc() and baFree().
void * AllocatorIntf::malloc | ( | size_t * | size | ) |
Returns pointer to uninitialized newly-allocated space for an object of size "size", or NULL on error.
size | the size required. The allocator can change the size to a size larger than the one requested. |
void * AllocatorIntf::realloc | ( | void * | p, |
size_t * | size | ||
) |
Returns pointer to newly-allocated space for an object of size "size", initialized, to minimum of old and new sizes, to existing contents of p (if non-null), or NULL on error.
On success, old object deallocated; otherwise unchanged.