vrq
Classes | Public Member Functions | Static Public Member Functions

CObstack Class Reference

Bulk object allocation object. More...

#include <cobstack.h>

List of all members.

Classes

struct  obstackChunk_tag
 obstack chunk definition

Public Member Functions

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

Static Public Member Functions

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

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:
name name of obstack (used for printing stats)
chunkSize allocation 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:
size number 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:
ptr pointer to block to copy.
size size 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:
ptr pointer to block to copy.
size size 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:
object if 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:
ptr pointer to block to copy.
size size in bytes of block to copy.
void CObstack::Grow ( INT32  size  ) 

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

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

Determine if pointer was allocated from this obstack.

Parameters:
ptr pointer 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:
ptr pointer to copy.

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