An alternate memory pager private heap manager. More...
#include <memory.h>
Public Member Functions | |
memalloc (size_t page=0) | |
Construct a memory pager. | |
virtual | ~memalloc () |
Destroy a memory pager. | |
unsigned | getPages (void) |
Get the number of pages that have been allocated from the real heap. | |
unsigned | getLimit (void) |
Get the maximum number of pages that are permitted. | |
unsigned | getAlloc (void) |
Get the size of a memory page. | |
unsigned | utilization (void) |
Determine fragmentation level of acquired heap pages. | |
void | purge (void) |
Purge all allocated memory and heap pages immediately. | |
virtual void * | alloc (size_t size) |
Allocate memory from the pager heap. | |
void * | zalloc (size_t size) |
Allocate memory from the pager heap. | |
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. | |
Protected Member Functions | |
page_t * | pager (void) |
Acquire a new page from the heap. | |
Protected Attributes | |
unsigned | limit |
An alternate memory pager private heap manager.
This is used to allocate in an optimized manner, as it assumes no mutex locks are held or used as part of it's own internal processing. It also is designed for optimized performance.
Definition at line 48 of file memory.h.
ucc::memalloc::memalloc | ( | size_t | page = 0 |
) |
Construct a memory pager.
page | size to use or 0 for OS allocation size. |
virtual ucc::memalloc::~memalloc | ( | ) | [virtual] |
Destroy a memory pager.
Release all pages back to the heap at once.
virtual void* ucc::memalloc::alloc | ( | size_t | size | ) | [virtual] |
Allocate memory from the pager heap.
The size of the request must be less than the size of the memory page used.
size | of memory request. |
Reimplemented in ucc::mempager.
void* ucc::memalloc::dup | ( | void * | memory, | |
size_t | size | |||
) |
Duplicate existing memory block into allocated memory.
memory | to data copy from. | |
size | of memory to allocate. |
Reimplemented in ucc::mempager.
char* ucc::memalloc::dup | ( | const char * | string | ) |
Duplicate NULL terminated string into allocated memory.
string | to copy into memory. |
Reimplemented in ucc::mempager.
unsigned ucc::memalloc::getAlloc | ( | void | ) | [inline] |
unsigned ucc::memalloc::getLimit | ( | void | ) | [inline] |
Get the maximum number of pages that are permitted.
One can use a derived class to set and enforce a maximum limit to the number of pages that will be allocated from the real heap. This is often used to detect and bring down apps that are leaking.
unsigned ucc::memalloc::getPages | ( | void | ) | [inline] |
Get the number of pages that have been allocated from the real heap.
Reimplemented in ucc::assoc_pointer< T, I, M, P >.
page_t* ucc::memalloc::pager | ( | void | ) | [protected] |
Acquire a new page from the heap.
This is mostly used internally.
unsigned ucc::memalloc::utilization | ( | void | ) |
Determine fragmentation level of acquired heap pages.
This is represented as an average % utilization (0-100) and represents the used portion of each allocated heap page vs the page size. Since requests that cannot fit on an already allocated page are moved into a new page, there is some unusable space left over at the end of the page. When utilization approaches 100, this is good. A low utilization may suggest a larger page size should be used.
Reimplemented in ucc::mempager, and ucc::assoc_pointer< T, I, M, P >.
void* ucc::memalloc::zalloc | ( | size_t | size | ) |
Allocate memory from the pager heap.
The size of the request must be less than the size of the memory page used. The memory is initialized to zero.
size | of memory request. |
Reimplemented in ucc::mempager.