Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
Data Structures | Functions
memory.h File Reference

Memory management header. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mem_stats
 Available to the user for display of memory statistics. 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...
 
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...
 
exceptionspMemException (void *vpCtx)
 Get a pointer to this memory objects's exception handler. More...
 

Detailed Description

Memory management header.

Definition in file memory.h.

Function Documentation

◆ bMemValidate()

abool bMemValidate ( void *  vpCtx)

Validates a memory context.

Parameters
vpCtxA pointer to a memory context.
Returns
APG_TRUE if the handle is valid, APG_FALSE otherwise.

Definition at line 160 of file memory.c.

◆ spMemException()

exception* spMemException ( void *  vpCtx)

Get a pointer to this memory objects's exception handler.

Parameters
vpCtxA pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code.
Returns
Pointer to this memory object's exception structure

Definition at line 174 of file memory.c.

◆ uiMemCount()

aint uiMemCount ( void *  vpCtx)

Returns the number of memory allocations.

Parameters
vpCtxA pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code.
Returns
Current number of allocations. vExContext() exception thrown if context pointer is invalid.

Definition at line 342 of file memory.c.

◆ vMemClear()

void vMemClear ( void *  vpCtx)

Frees all memory allocations.

Parameters
vpCtxA pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code.

Definition at line 361 of file memory.c.

◆ vMemDtor()

void vMemDtor ( void *  vpCtx)

Destroys a Memory component. Frees all memory allocated.

Parameters
vpCtxA 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.

Definition at line 141 of file memory.c.

◆ vMemFree()

void vMemFree ( void *  vpCtx,
const void *  vpData 
)

Free memory previously allocated with vpMemAlloc().

Parameters
vpCtxA pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code.
vpDataPointer 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.

Definition at line 226 of file memory.c.

◆ vMemStats()

void vMemStats ( void *  vpCtx,
mem_stats spStats 
)

Returns a copy of the Memory component's current statistics.

Parameters
vpCtxA pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code.
spStatspointer to a user-supplied statistics buffer.
Returns
void

Definition at line 456 of file memory.c.

◆ vpMemAlloc()

void* vpMemAlloc ( void *  vpCtx,
aint  uiBytes 
)

Allocates memory.

Note that uiBytes + sizeof(mem_cell) is actually allocated on the heap.

  • The data is | cell struct | ... user data ... |
  • The actual malloc() heap allocation is at cell struct
  • The user data area is at heap allocation address + sizeof(cell struct)
    Parameters
    vpCtxA pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code.
    uiBytesthe number of bytes of memory to allocate
    Returns
    a pointer to the user data portion of the allocated memory. Exception thrown on memory allocation failure.

Definition at line 196 of file memory.c.

◆ vpMemCtor()

void* vpMemCtor ( exception spException)

Construct a memory component.

Parameters
spExceptionPointer to a valid exception structure initialized with vExCtor() or XCTOR(). If invalid the application will silently exit with a BAD_CONTEXT exit code.
Returns
Pointer to a memory object context on success. Throws exception on memory allocation failure.

Definition at line 121 of file memory.c.

◆ vpMemRealloc()

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.

Parameters
vpCtxA pointer to a valid memory context previously returned from vpMemCtor(). If invalid the application will silently exit with a BAD_CONTEXT exit code.
vpDataPointer to the data to free. An invalid pointer - a pointer not previously returned from vpMemAlloc() or vpMemRealloc() - will result in a thrown exception.
uiBytesnumber of re-allocated bytes of memory. Must be > 0;
Returns
pointer to the re-allocated memory. Throws exception on memory allocation error, invalid data pointer error or uiBytes=0.

Definition at line 268 of file memory.c.

APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.