FastObjT Class Template Reference

List of all members.

Detailed Description

template<typename T, size_t A = sizeof(void*), size_t CS = details::DEFAULT_CHUNK_SIZE>
class omni::pool::FastObjT< T, A, CS >

Fast object with individual pool.

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.

Parameters:
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.
Example of using the FastObjT class:

  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.

See also:
Fast memory management.

Public Types

Static Public Member Functions

Protected Member Functions


Member Typedef Documentation

typedef ObjPool<A> pool_type

The pool type.


Member Enumeration Documentation

anonymous enum

Constants.

Enumerator:
CHUNK_SIZE  Approximate chunk size.
ALIGNMENT  Alignment of objects.


Constructor & Destructor Documentation

FastObjT (  )  [inline, protected]

Trivial constructor.

~FastObjT (  )  [inline, protected]

Trivial destructor.


Member Function Documentation

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)!

Exceptions:
std::bad_alloc If there's no available memory.
Parameters:
[in] buf_size The memory block size.
Returns:
The memory block.

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.

Parameters:
[in] buf_size The memory block size.
Returns:
The memory block or null.

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.

Parameters:
[in] buf_size The memory block size.
[in] p The memory block.
Returns:
The memory block.

static void operator delete ( void *  buf  )  [inline, static]

The memory deallocation.

This operator deallocates the buf memory block.

Parameters:
[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.

Parameters:
[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.

Parameters:
[in] buf The memory block?
[in] p The memory block?


Generated on Wed Jun 6 17:27:47 2007 for OMNI by  doxygen 1.5.2