UCommon
|
A class to hold memory pointers referenced by string names. More...
#include <memory.h>
Public Member Functions | |
bool | assign (char *name, void *pointer) |
Assign a name to a data pointer. | |
bool | create (char *name, void *pointer) |
Create a new name in the association table and assign it's value. | |
unsigned | getCount (void) |
Get the number of associations we have in our object. | |
keyassoc (unsigned indexing=177, size_t max=0, size_t page=0) | |
Create a key associated memory pointer table. | |
void * | locate (char *name) |
Lookup the data pointer by the string name given. | |
void * | operator() (char *name) |
Lookup the data pointer of a string by direct operation. | |
void | purge (void) |
Purge all associations and return allocated pages to heap. | |
void * | remove (char *name) |
Remove a name and pointer association. | |
~keyassoc () | |
Destroy association object. |
Friends | |
class | keydata |
Additional Inherited Members | |
![]() | |
virtual void * | _alloc (size_t size) |
Allocate memory from the pager heap. | |
virtual void | dealloc (void *memory) |
Return memory back to pager heap. | |
mempager (size_t page=0) | |
Construct a memory pager. | |
unsigned | utilization (void) |
Determine fragmentation level of acquired heap pages. | |
virtual | ~mempager () |
Destroy a memory pager. | |
virtual void | _lock (void) |
Lock the memory pager mutex. | |
virtual void | _unlock (void) |
Unlock the memory pager mutex. | |
![]() | |
unsigned | getAlloc (void) |
Get the size of a memory page. | |
unsigned | getLimit (void) |
Get the maximum number of pages that are permitted. | |
unsigned | getPages (void) |
Get the number of pages that have been allocated from the real heap. | |
memalloc (size_t page=0) | |
Construct a memory pager. | |
virtual | ~memalloc () |
Destroy a memory pager. | |
![]() | |
void * | alloc (size_t size) |
Convenience function. | |
char * | dup (const char *string) |
Duplicate NULL terminated string into allocated memory. | |
void * | dup (void *memory, size_t size) |
Duplicate existing memory block into allocated memory. | |
void * | zalloc (size_t size) |
Allocate memory from the pager heap. |
A class to hold memory pointers referenced by string names.
This is used to form a typeless data pointer that can be associated and referenced by string/logical name. The memory used for forming the string names can itself be managed in reusable memory pools and the entire structure uses it's own private pager heap. This allows new string named pointers to be added and deleted at runtime in a thread- safe manner. This might typically be used as a session id manager or for symbol tables.
ucommon::keyassoc::keyassoc | ( | unsigned | indexing = 177 , |
size_t | max = 0 , |
||
size_t | page = 0 |
||
) |
Create a key associated memory pointer table.
indexing | size for hash map. |
max | size of a string name if names are in reusable managed memory. |
page | size of memory pager. |
ucommon::keyassoc::~keyassoc | ( | ) |
Destroy association object.
Release all pages back to the heap.
bool ucommon::keyassoc::assign | ( | char * | name, |
void * | pointer | ||
) |
Assign a name to a data pointer.
If the name exists, it is re-assigned with the new pointer value, otherwise it is created.
name | to assign. |
pointer | value to assign with name. |
bool ucommon::keyassoc::create | ( | char * | name, |
void * | pointer | ||
) |
Create a new name in the association table and assign it's value.
name | to create. |
pointer | value to assign with name. |
|
inline |
Get the number of associations we have in our object.
Reimplemented in ucommon::assoc_pointer< T, I, M, P >.
void* ucommon::keyassoc::locate | ( | char * | name | ) |
Lookup the data pointer by the string name given.
name | to lookup. |
Reimplemented in ucommon::assoc_pointer< T, I, M, P >.
|
inline |
Lookup the data pointer of a string by direct operation.
name | to lookup. |
Reimplemented in ucommon::assoc_pointer< T, I, M, P >.
void* ucommon::keyassoc::remove | ( | char * | name | ) |
Remove a name and pointer association.
If managed key names are used then the memory allocated for the name will be re-used.
name | to remove. |
Reimplemented in ucommon::assoc_pointer< T, I, M, P >.