A generic class that handles memory pools. More...
#include <ilog/pool.h>
Static Public Member Functions |
|
| static TYPE * | Alloc (IlUInt nElements, IlBoolean lock=IlFalse) |
| Allocates a block of memory. More... |
|
| static TYPE * | Lock (TYPE *data) |
| Locks a data block. More... |
|
| static TYPE * | ReAlloc (TYPE *data, IlUInt nElements, IlBoolean lock=IlFalse) |
| Re-allocates a data block. More... |
|
| static TYPE * | UnLock (TYPE *data) |
| Unlocks a data block. More... |
|
Detailed Description
A generic class that handles memory pools.
Library: ilog
Memory pools offer the advantage of greatly simplifying the handling the allocation, locking and deallocation of chunks of memory that can be used by your applications.
The complete body of this class is generated by the macros IlDeclarePoolOf_OPENPAR_NAME, TYPE_CLOSEPAR_ and IlDefinePoolOf_OPENPAR_NAME, TYPE_CLOSEPAR_, that respectively declare and define a class called IlPoolOf(NAME) that manages a memory pool for objects of the type TYPE.
A given pool can manage only arrays of TYPE, but it can manage as many of those memory blocks as needed. To get an array, you simply call the static member function IlPoolOf(NAME)::Alloc(n);, and a memory block large enough to hold n elements of type TYPE will be returned to you.
Note that if you repeat this call, you may receive the same memory block (because it may already be large enough to fit your needs). If you actually want another block to be allocated and returned to you, you must lock the first block, using the static member function IlPoolOf(NAME)::Lock(data);. This ensures that the next call to Alloc() will not return the same memory block. To unlock a memory block that you have locked, you must call UnLock().
Many functions in Rogue Wave Views will return memory blocks that are managed by pools. Therefore:
- You should never delete such a memory block.
- If you need to temporarily keep this block in your code and perform calls to Rogue Wave Views in the meantime, you must lock the memory block that was returned to you and unlock it when you are finished with it.
Member Function Documentation
◆ Alloc()
Allocates a block of memory.
- Parameters
-
nElements The number of elements to allocate. lock Set this to IlTrueto lock the associated data block.
- Returns
- A pointer to an array of pointers to
TYPE. This pointer is managed by a new data block or a data block that is not locked.
◆ Lock()
|
static |
Locks a data block.
Locking a data block ensures that no allocation request on this pool will be authorized to return this block.
- Parameters
-
data The data block to be locked.
- Returns
- data The data block.
◆ ReAlloc()
|
static |
Re-allocates a data block.
- Parameters
-
data The data block to be re-allocated. nElements The number of elements that are needed. lock Can be set to IlTrueto lock the returned data block.
- Returns
- The re-allocated data block. This may not be equal to data, but the content of data is copied in this new block.
◆ UnLock()
|
static |
Unlocks a data block.
When you unlock a data block, any allocation request on this pool is authorized to return the same data block.
- Parameters
-
data The data block to be unlocked.
- Returns
- The data block.
