vrq
Classes | Public Member Functions | Static Public Member Functions | List of all members
CObstack Class Reference

Bulk object allocation object. More...

#include <cobstack.h>

Public Member Functions

 CObstack (const char *name, int chunkSize=OBSTACK_DEFAULT_BLOCK_SIZE)
 Create object stack with given chunk size. More...
 
 ~CObstack (void)
 Destroy and free object stack storage. More...
 
void * Alloc (INT32 size)
 Allocate block of storage with given size. More...
 
void Free (void *object)
 Free all storage including and after object. More...
 
void * GetBase (void)
 Get base of current object. More...
 
void * NextFree (void)
 Get next free byte of current object. More...
 
void * Finish (void)
 Finialized the object. More...
 
void * Copy (const void *ptr, INT32 size)
 Allocate storage and copy block of memory to heap. More...
 
void * Copy0 (const void *ptr, INT32 size)
 Allocate storage and copy block of memory with a byte of 0 to heap. More...
 
INT32 GetObjectSize (void)
 Get size of current open object. More...
 
void Grow (const void *ptr, INT32 size)
 Grow current object and copy block of data to heap. More...
 
void Grow (INT32 size)
 Grow current object Object stays open and can be grown further. More...
 
void PtrGrow (void *ptr)
 Grow current object and copy pointer to heap. More...
 
int IsOwner (void *ptr)
 Determine if pointer was allocated from this obstack. More...
 

Static Public Member Functions

static void OnExitDumpStats ()
 OnExitDumpStats Dump memory allocation stats for each obstack at exit. More...
 

Detailed Description

Bulk object allocation object.

Objects are allocated one at a time, but freed all at once. This is very efficient for both persistant and temporary storage.

Constructor & Destructor Documentation

CObstack::CObstack ( const char *  name,
int  chunkSize = OBSTACK_DEFAULT_BLOCK_SIZE 
)

Create object stack with given chunk size.

Parameters
namename of obstack (used for printing stats)
chunkSizeallocation block size. Optional parameter defaults to OBSTACK_DEFAULT_BLOCK_SIZE
CObstack::~CObstack ( void  )

Destroy and free object stack storage.

Member Function Documentation

void* CObstack::Alloc ( INT32  size)

Allocate block of storage with given size.

Parameters
sizenumber of bytes to allocate.
Returns
pointer to storage.
void* CObstack::Copy ( const void *  ptr,
INT32  size 
)

Allocate storage and copy block of memory to heap.

Parameters
ptrpointer to block to copy.
sizesize in bytes of block to copy.
Returns
finalized pointer to block on heap.
void* CObstack::Copy0 ( const void *  ptr,
INT32  size 
)

Allocate storage and copy block of memory with a byte of 0 to heap.

Parameters
ptrpointer to block to copy.
sizesize in bytes of block to copy.
Returns
finalized pointer to block on heap.
void* CObstack::Finish ( void  )

Finialized the object.

After this call the object cannot be grown. The pointer returned will not be relocated after this point.

Returns
pointer to base of object.
void CObstack::Free ( void *  object)

Free all storage including and after object.

Parameters
objectif object is NULL, free all objects on heap.
void* CObstack::GetBase ( void  )

Get base of current object.

Object has not been finalized so pointer may change as more space is allocated.

Returns
pointer to base.
INT32 CObstack::GetObjectSize ( void  )

Get size of current open object.

Returns
size in bytes of current object.
void CObstack::Grow ( const void *  ptr,
INT32  size 
)

Grow current object and copy block of data to heap.

Object stays open and can be grown further.

Parameters
ptrpointer to block to copy.
sizesize in bytes of block to copy.
void CObstack::Grow ( INT32  size)

Grow current object Object stays open and can be grown further.

Parameters
sizenumber of bytes to grow object .
int CObstack::IsOwner ( void *  ptr)

Determine if pointer was allocated from this obstack.

Parameters
ptrpointer to block.
Returns
non-zero if block was allocated from this obstack.
void* CObstack::NextFree ( void  )

Get next free byte of current object.

Object has not been finalized so pointer may change as more space is allocated.

Returns
pointer to base.
static void CObstack::OnExitDumpStats ( )
static

OnExitDumpStats Dump memory allocation stats for each obstack at exit.

void CObstack::PtrGrow ( void *  ptr)

Grow current object and copy pointer to heap.

Object stays open and can be grown further.

Parameters
ptrpointer to copy.

The documentation for this class was generated from the following file: