The FastObjT class contains individual pool object. The new / delete operators of this class use this individual pool object.
To use fast memory management your class should be derived from the FastObjT<> class. See the example below.
Since the pool object can manage only one memory block size, the FastObjT class can't be used with polymorphic classes.
T | Object type. This object type is used to determine memory block size. The memory block size is equal to sizeof(T). | |
A | Alignment of pointers. Should be integer power of two. | |
CS | Approximate memory chunk size in bytes. |
class Packet: public omni::pool::FastObjT<Packet> { public: char data[188]; // 188 bytes data payload int a, b; // custom parameters }; void f() { Packet *p1 = new Packet(); // ObjPool::get() used // ... delete p1; // ObjPool::put() used // ... Packet *p2 = new Packet(); // ObjPool::get() used // ... delete p2; // ObjPool::put() used }
Note: The Packet class is derived from FastObjT<Packet>. The same technique is widely used in WTL library.
anonymous enum |
FastObjT | ( | ) | [inline, protected] |
Trivial constructor.
~FastObjT | ( | ) | [inline, protected] |
Trivial destructor.
static void* operator new | ( | size_t | buf_size | ) | [inline, static] |
The memory allocation.
This operator allocates the buf_size bytes memory block. Argument buf_size should be less than or equal to the sizeof(T)!
std::bad_alloc | If there's no available memory. |
[in] | buf_size | The memory block size. |
static void* operator new | ( | size_t | buf_size, | |
const std::nothrow_t & | ||||
) | [inline, static] |
The memory allocation.
This operator allocates the buf_size bytes memory block. Argument buf_size should be less than or equal to the sizeof(T)!
If there is no available memory, then this operator will return null pointer.
[in] | buf_size | The memory block size. |
static void* operator new | ( | size_t | buf_size, | |
void * | p | |||
) | [inline, static] |
Placement new operator.
This operator is used only for correct overloading of other new operators. It uses global placement new operator.
[in] | buf_size | The memory block size. |
[in] | p | The memory block. |
static void operator delete | ( | void * | buf | ) | [inline, static] |
The memory deallocation.
This operator deallocates the buf memory block.
[in] | buf | The memory block. |
static void operator delete | ( | void * | buf, | |
const std::nothrow_t & | ||||
) | [inline, static] |
The memory deallocation.
This operator deallocates the buf memory block.
[in] | buf | The memory block. |
static void operator delete | ( | void * | buf, | |
void * | p | |||
) | [inline, static] |
Placement delete operator?
This operator is used only for correct overloading of other delete operators. It uses global placement delete operator.
[in] | buf | The memory block? |
[in] | p | The memory block? |