Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
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 ()
 Leave callbacks uninitialized; initialize them before use. More...
 
 AllocatorIntf (AllocatorIntf_Malloc malloc, AllocatorIntf_Realloc realloc, AllocatorIntf_Free free)
 Create an instance of a memory allocation class. More...
 
void * malloc (size_t *size)
 Allocate uninitialized storage. More...
 
void * malloc (size_t size)
 Allocate without returning the adjusted allocation size. More...
 
void * realloc (void *p, size_t *size)
 Resize an allocation. More...
 
void * realloc (void *p, size_t size)
 Resize without returning the adjusted allocation size. More...
 
void free (void *p)
 Release an allocation. More...
 

Static Public Member Functions

static AllocatorIntf * getDefault (void)
 Obtain the shared allocator backed by baMalloc, baRealloc and baFree. More...
 

Constructor & Destructor Documentation

◆ AllocatorIntf() [1/2]

AllocatorIntf::AllocatorIntf ( )

Leave callbacks uninitialized; initialize them before use.

◆ AllocatorIntf() [2/2]

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
mallocRequired allocation callback, retained without copying.
reallocPointer to memory reallocation method. This method is optional and the argument can be set to NULL if not implemented.
freeRequired deallocation callback, retained without copying.

Member Function Documentation

◆ free()

void AllocatorIntf::free ( void *  p)

Release an allocation.

Parameters
[in]pLive block from this allocator. NULL is allowed only if the installed callback supports it; see AllocatorIntf_Free.

◆ getDefault()

AllocatorIntf * AllocatorIntf::getDefault ( void  )
static

Obtain the shared allocator backed by baMalloc, baRealloc and baFree.

Returns
Borrowed process-lifetime allocator; do not free it or change its callbacks.

◆ malloc() [1/2]

void * AllocatorIntf::malloc ( size_t *  size)

Allocate uninitialized storage.

Parameters
[in,out]sizeRequested byte count, possibly increased on success.
Returns
Allocated block or NULL; see AllocatorIntf_Malloc.

◆ malloc() [2/2]

void * AllocatorIntf::malloc ( size_t  size)

Allocate without returning the adjusted allocation size.

Parameters
[in]sizeRequested byte count.
Returns
Allocated block or NULL; see AllocatorIntf_Malloc.

◆ realloc() [1/2]

void * AllocatorIntf::realloc ( void *  p,
size_t *  size 
)

Resize an allocation.

Parameters
[in]pBlock allocated by this allocator, or NULL.
[in,out]sizeRequested byte count, possibly increased on success.
Returns
Replacement block or NULL. If realloc is not implemented, returns NULL without modifying p or size. See AllocatorIntf_Realloc.

◆ realloc() [2/2]

void * AllocatorIntf::realloc ( void *  p,
size_t  size 
)

Resize without returning the adjusted allocation size.

Parameters
[in]pBlock allocated by this allocator, or NULL.
[in]sizeRequested byte count.
Returns
Replacement block or NULL; see AllocatorIntf_Realloc.