csMemoryPool Class Reference
[Containers]
A quick-allocation pool for storage of arbitrary data.
More...
#include <csutil/mempool.h>
Public Member Functions | |
void * | Alloc (size_t) |
Allocate the specified number of bytes. | |
csMemoryPool (size_t gran=4096) | |
Construct a new memory pool. | |
void | Empty () |
Release all memory allocated by the pool. | |
char const * | Store (char const *) |
Store a null-terminated C-string. | |
void const * | Store (void const *, size_t) |
Store a copy of a block of memory of the indicated size. | |
~csMemoryPool () | |
Destroy the memory pool, freeing all allocated storage. |
Detailed Description
A quick-allocation pool for storage of arbitrary data.Pointers to allocations made from the pool are guaranteed to remain valid as long as the pool is alive; the pool contents are never relocated. All individually allocated memory chunks are freed when the pool itself is destroyed. This memory management scheme is suitable for algorithms which need to allocate and manipulate many chunks of memory in a non-linear fashion where the life-time of each memory chunk is not predictable. Rather than complicating the algorithm by having it carefully track each memory chunk to determine when it would be safe to dispose of the memory, it can instead create a csMemoryPool at the start, and destroy the pool at the end. During processing, it can allocate memory chunks from the pool as needed, and simply forget about them when no longer needed, knowing that they will be freed en-masse when the pool itself is disposed. This is often a cheaper, simpler, and faster alternative to reference-counting or automatic garbage collection.
- See also:
- csBlockAllocator
Definition at line 58 of file mempool.h.
Constructor & Destructor Documentation
|
Construct a new memory pool. If a size is provided, it is taken as a recommendation in bytes of the granularity of the internal allocations made by the pool, but is not a hard limit. Client allocations from the pool can be both smaller and larger than this number. A larger number will result in fewer interactions with the system heap (which translates to better performance), but at the cost of potential unused but allocated space. A smaller number translates to a greater number of interactions with the system heap (which is slow), but means less potential wasted memory. |
|
Destroy the memory pool, freeing all allocated storage.
|
Member Function Documentation
|
Allocate the specified number of bytes.
Referenced by operator new(). |
|
Release all memory allocated by the pool.
|
|
Store a null-terminated C-string.
|
|
Store a copy of a block of memory of the indicated size.
|
The documentation for this class was generated from the following file:
- csutil/mempool.h
Generated for Crystal Space by doxygen 1.4.6