Version 6.3
Copyright © 2005 - 2012 Lowell D. Thomas
APG
  … ABNF Parser Generator
All Data Structures Files Functions Variables Typedefs Macros Pages
Functions
Memory.c File Reference

The Memory component API. More...

#include "Apg.h"
#include "Private.h"

Go to the source code of this file.

Functions

void * vpMemCtorA (PFN_ALLOCATOR pfnAllocator, PFN_DEALLOCATOR pfnDeAllocator)
 
void * vpMemCtor ()
 
void vMemDtor (void *vpCtx)
 
apg_uint uiMemValidate (void *vpCtx)
 
void * vpMemAlloc (void *vpCtx, apg_uint uiBytes)
 
void vMemFree (void *vpCtx, void *vpData)
 
void * vpMemRealloc (void *vpCtx, void *vpData, apg_uint uiBytes)
 
apg_uint uiMemCheckPoint (void *vpCtx)
 
void vMemFreeToCheckPoint (void *vpCtx, apg_uint uiChk)
 
void vMemClear (void *vpCtx)
 
apg_uint uiMemStats (void *vpCtx, APG_MEM_STATS *spStats)
 

Detailed Description

The Memory component API.

The Memory component is a simple, doubly-linked list of "cells". A cell is simply a data struct of linked list pointers and memory allocation information.

Definition in file Memory.c.

Function Documentation

◆ uiMemCheckPoint()

apg_uint uiMemCheckPoint ( void *  vpCtx)

Returns a check point to the current state of the memory component. Can be used later to restore the current state.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
See also
vpMemCtor()
vpMemCtorA()
vMemFreeToCheckPoint()
Returns
current state

Definition at line 230 of file Memory.c.

◆ uiMemStats()

apg_uint uiMemStats ( void *  vpCtx,
APG_MEM_STATS spStats 
)

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

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
spStatspointer to a user-supplied statistics buffer. May be NULL, in which case only the required size of the statistics buffer is returned.
See also
vpMemCtor()
vpMemCtorA()
APG_MEM_STATS
Returns
the required size of the statistics buffer.

Definition at line 287 of file Memory.c.

◆ uiMemValidate()

apg_uint uiMemValidate ( void *  vpCtx)

Validates a Memory context handle.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
See also
vpMemCtor()
vpMemCtorA()
Returns
true if the handle is valid, false otherwise.

Definition at line 115 of file Memory.c.

◆ vMemClear()

void vMemClear ( void *  vpCtx)

Frees all memory allocations from this Memory component.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA(). NULL pointers are silently ignored.
See also
vpMemCtor()
vpMemCtorA()

Definition at line 277 of file Memory.c.

◆ vMemDtor()

void vMemDtor ( void *  vpCtx)

Destroys a Memory component.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA(). NULL pointers are silently ignored.
See also
vpMemCtor()
vpMemCtorA()

Definition at line 97 of file Memory.c.

◆ vMemFree()

void vMemFree ( void *  vpCtx,
void *  vpData 
)

De-allocates memory previously allocated with vpMemAlloc().

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA(). NULL pointers are silently ignored.
vpDatapointer to the memory allocation to free. If NULL, silently ignored.
See also
vpMemCtor()
vpMemCtorA()
vpMemAlloc()

Definition at line 157 of file Memory.c.

◆ vMemFreeToCheckPoint()

void vMemFreeToCheckPoint ( void *  vpCtx,
apg_uint  uiChk 
)

Restores a previous state of the Memory component.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA(). NULL pointers are silently ignored.
uiChkthe previous state to restore. Must be from a previous call to uiMemCheckPoint().
See also
vpMemCtor()
vpMemCtorA()
uiMemCheckPoint()

Definition at line 250 of file Memory.c.

◆ vpMemAlloc()

void* vpMemAlloc ( void *  vpCtx,
apg_uint  uiBytes 
)

Allocates memory.

Parameters
vpCtxa Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
uiBytesthe number of bytes of memory to allocate
See also
vpMemCtor()
vpMemCtorA()
vMemFree()
Returns
a pointer to the allocated memory, NULL on allocation failure.

Definition at line 130 of file Memory.c.

◆ vpMemCtor()

void* vpMemCtor ( )

Constructs a Memory component using malloc() as the memory allocator and free() as the de-allocator.

Returns
a Memory context handle (void pointer to an opaque data struct). NULL on failure.

Definition at line 77 of file Memory.c.

◆ vpMemCtorA()

void* vpMemCtorA ( PFN_ALLOCATOR  pfnAllocator,
PFN_DEALLOCATOR  pfnDeAllocator 
)

Constructs a Memory component using a user-defined memory allocator and de-allocator.

Parameters
pfnAllocatorpointer to a user-defined memory allocator
pfnDeAllocatorpointer to a user-defined memory de-allocator
Returns
a Memory context handle (void pointer to an opaque data struct). NULL on failure.

Definition at line 56 of file Memory.c.

◆ vpMemRealloc()

void* vpMemRealloc ( void *  vpCtx,
void *  vpData,
apg_uint  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 Memory context handle previously returned from vpMemCtor(), or vpMemCtorA().
vpDatapointer to the memory to be re-allocated.
uiBytesnumber of re-allocated bytes of memory.
See also
vpMemCtor()
vpMemCtorA()
vpMemAlloc()()
Returns
pointer to the re-allocated memory. NULL if re-allocation failed.

Definition at line 182 of file Memory.c.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/licenses.html or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.