![]() |
![]() |
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... | |
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.
CObstack::CObstack | ( | const char * | name, |
int | chunkSize = OBSTACK_DEFAULT_BLOCK_SIZE |
||
) |
Create object stack with given chunk size.
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.
void* CObstack::Alloc | ( | INT32 | size | ) |
Allocate block of storage with given size.
size | number of bytes to allocate. |
void* CObstack::Copy | ( | const void * | ptr, |
INT32 | size | ||
) |
Allocate storage and copy block of memory to heap.
ptr | pointer to block to copy. |
size | size in bytes of block to copy. |
void* CObstack::Copy0 | ( | const void * | ptr, |
INT32 | size | ||
) |
Allocate storage and copy block of memory with a byte of 0 to heap.
ptr | pointer to block to copy. |
size | size in bytes of block to copy. |
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.
void CObstack::Free | ( | void * | object | ) |
Free all storage including and after object.
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.
INT32 CObstack::GetObjectSize | ( | void | ) |
Get size of current open 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.
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.
size | number of bytes to grow object . |
int CObstack::IsOwner | ( | void * | ptr | ) |
Determine if pointer was allocated from this obstack.
ptr | pointer to block. |
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.
|
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.
ptr | pointer to copy. |