APG
… an ABNF Parser Generator
|
The memory management object. More...
Go to the source code of this file.
Data Structures | |
struct | mem_cell_tag |
A circularly-linked list structure. More... | |
struct | mem |
For internal use only. The memory object's context. Opaque to user applications. More... | |
Functions | |
void * | vpMemCtor (exception *spException) |
Construct a memory component. More... | |
void | vMemDtor (void *vpCtx) |
Destroys a Memory component. Frees all memory allocated. More... | |
abool | bMemValidate (void *vpCtx) |
Validates a memory context. More... | |
exception * | spMemException (void *vpCtx) |
Get a pointer to this memory objects's exception handler. More... | |
void * | vpMemAlloc (void *vpCtx, aint uiBytes) |
Allocates memory. More... | |
void | vMemFree (void *vpCtx, const void *vpData) |
Free memory previously allocated with vpMemAlloc(). More... | |
void * | vpMemRealloc (void *vpCtx, const void *vpData, aint uiBytes) |
Re-allocates memory previously allocated with vpMemAlloc(). More... | |
aint | uiMemCount (void *vpCtx) |
Returns the number of memory allocations. More... | |
void | vMemClear (void *vpCtx) |
Frees all memory allocations. More... | |
void | vMemStats (void *vpCtx, mem_stats *spStats) |
Returns a copy of the Memory component's current statistics. More... | |
Statistics Collection Macros used by the memory object. | |
If APG_MEM_STATS is defined, these 3 macros will be defined to call the statistics gathering functions. If APG_MEM_STATS is not defined, these macros generate no code. | |
#define | STATS_ALLOC(s, i) vStatsAlloc((s), (i)) |
Called by the memory object to count memory allocations. More... | |
#define | STATS_FREE(s, i) vStatsFree((s), (i)) |
Called by the memory object to count memory frees. More... | |
#define | STATS_REALLOC(s, i, o) vStatsRealloc((s), (i), (o)) |
Called by the memory object to count memory re-allocations. More... | |
The memory management object.
This file holds the memory management class or object. Almost all APG objects and applications use this memory object for control of all memory allocations and frees. A primary feature of this object is that its destruction automatically frees all memory allocations that have been made with it. Memory allocation failures are reported with an exception thrown to the parent application's catch block. This frees the application of all the burdensome code for checking the return and handling an error for each and every allocation.
Definition in file memory.c.
#define STATS_ALLOC | ( | s, | |
i | |||
) | vStatsAlloc((s), (i)) |
#define STATS_FREE | ( | s, | |
i | |||
) | vStatsFree((s), (i)) |
#define STATS_REALLOC | ( | s, | |
i, | |||
o | |||
) | vStatsRealloc((s), (i), (o)) |
abool bMemValidate | ( | void * | vpCtx | ) |
exception* spMemException | ( | void * | vpCtx | ) |
Get a pointer to this memory objects's exception handler.
vpCtx | A pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code. |
aint uiMemCount | ( | void * | vpCtx | ) |
Returns the number of memory allocations.
vpCtx | A pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code. |
void vMemClear | ( | void * | vpCtx | ) |
Frees all memory allocations.
vpCtx | A pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code. |
void vMemDtor | ( | void * | vpCtx | ) |
Destroys a Memory component. Frees all memory allocated.
vpCtx | A pointer to a valid memory context previously returned from vpMemCtor(). Silently ignored if NULL. However, if non-NULL it must be a valid memory context pointer. |
void vMemFree | ( | void * | vpCtx, |
const void * | vpData | ||
) |
Free memory previously allocated with vpMemAlloc().
vpCtx | A pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code. |
vpData | Pointer to the data to free. A NULL pointer is silently ignored. However, an invalid pointer - a pointer not previously returned from vpMemAlloc() or vpMemRealloc() - will result in a thrown exception. vExContext() exception thrown if context pointer is invalid. |
void vMemStats | ( | void * | vpCtx, |
mem_stats * | spStats | ||
) |
Returns a copy of the Memory component's current statistics.
vpCtx | A pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code. |
spStats | pointer to a user-supplied statistics buffer. |
void* vpMemAlloc | ( | void * | vpCtx, |
aint | uiBytes | ||
) |
Allocates memory.
Note that uiBytes + sizeof(mem_cell) is actually allocated on the heap.
vpCtx | A pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code. |
uiBytes | the number of bytes of memory to allocate |
void* vpMemCtor | ( | exception * | spException | ) |
Construct a memory component.
spException | Pointer to a valid exception structure initialized with vExCtor() or XCTOR(). If invalid the application will silently exit with a BAD_CONTEXT exit code. |
void* vpMemRealloc | ( | void * | vpCtx, |
const void * | vpData, | ||
aint | uiBytes | ||
) |
Re-allocates memory previously allocated with vpMemAlloc().
Can be used to up-size or down-size a memory allocation. Any previous data in the memory allocation is copied to the re-allocation.
vpCtx | A pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code. |
vpData | Pointer to the data to free. An invalid pointer - a pointer not previously returned from vpMemAlloc() or vpMemRealloc() - will result in a thrown exception. |
uiBytes | number of re-allocated bytes of memory. Must be > 0; |