Barracuda Application Server C/C++ Reference
NO
AllocatorIntf Struct Reference

Detailed Description

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>

Inheritance diagram for AllocatorIntf:

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 AllocatorIntfgetDefault (void)
 Returns a pointer to a predefined AllocatorIntf class. More...
 

Constructor & Destructor Documentation

◆ AllocatorIntf()

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.

Parameters
mallocPointer to memory allocation method.
reallocPointer to memory reallocation method. This method is optional and the argument can be set to NULL if not implemented.
freePointer to a memory deallocation method.

Member Function Documentation

◆ getDefault()

AllocatorIntf * AllocatorIntf::getDefault ( void  )
static

Returns a pointer to a predefined AllocatorIntf class.

The default implementation uses method baMalloc(), baRealloc() and baFree().

◆ malloc()

void * AllocatorIntf::malloc ( size_t *  size)

Returns pointer to uninitialized newly-allocated space for an object of size "size", or NULL on error.

Parameters
sizethe size required. The allocator can change the size to a size larger than the one requested.

◆ realloc()

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.