C/C++ Reference
Dynamic memory handling.

Classes

struct  AllocatorIntf
 Memory allocation and deallocation Interface class. More...
struct  FixedSizeAllocator
 This is a fixed size allocator implementation for the abstract interface class AllocatorIntf. More...

Typedefs

typedef void *(* AllocatorIntf_Malloc )(struct AllocatorIntf *o, size_t *size)
 Malloc prototype.
typedef void *(* AllocatorIntf_Realloc )(struct AllocatorIntf *o, void *memblock, size_t *size)
 Realloc prototype.
typedef void(* AllocatorIntf_Free )(struct AllocatorIntf *o, void *memblock)
 Free prototype.
typedef struct AllocatorIntf AllocatorIntf
 Memory allocation and deallocation Interface class.
typedef FixedSizeAllocator FixedSizeAllocator
 This is a fixed size allocator implementation for the abstract interface class AllocatorIntf.

Functions

void * baMalloc (size_t size)
 Returns pointer to uninitialized newly-allocated space for an object of size "size", or NULL on error.
void * baRealloc (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.
void baFree (void *p)
 Deallocates space to which it points.
 AllocatorIntf::AllocatorIntf (AllocatorIntf_Malloc malloc, AllocatorIntf_Realloc realloc, AllocatorIntf_Free free)
 Create an instance of a memory allocation class.
static AllocatorIntfAllocatorIntf::getDefault (void)
 Returns a pointer to a predefined AllocatorIntf class.
void * AllocatorIntf::malloc (size_t *size)
 Returns pointer to uninitialized newly-allocated space for an object of size "size", or NULL on error.
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.
void AllocatorIntf::free (void *p)
 Deallocates space to which it points.

Detailed Description

See also:
Barracuda Introduction

Typedef Documentation

typedef struct AllocatorIntf AllocatorIntf

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.

typedef void(* AllocatorIntf_Free)(struct AllocatorIntf *o, void *memblock)

Free prototype.

See also:
AllocatorIntf::AllocatorIntf
typedef void*(* AllocatorIntf_Malloc)(struct AllocatorIntf *o, size_t *size)

Malloc prototype.

Parameters:
sizethe size required. The allocator can change the size to a size larger than the one requested.
See also:
AllocatorIntf::AllocatorIntf
typedef void*(* AllocatorIntf_Realloc)(struct AllocatorIntf *o, void *memblock, size_t *size)

Realloc prototype.

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

This is a fixed size allocator implementation for the abstract interface class AllocatorIntf.

The FixedSizeAllocator takes a buffer and splits the buffer up into equally sized chunks. Allocating memory larger than the chunk size or using realloc results in an error; i.e., NULL returned. One can allocate a smaller size than the chunk size, but the size will be adjusted to the chunk size.


Function Documentation

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.
void* baRealloc ( 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.

AllocatorIntf * AllocatorIntf::getDefault ( void  ) [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.

Parameters:
sizethe 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.