atomic_class_pool< T > Struct Template Reference

Inherits atomic_preallocated_pool.

Inheritance diagram for atomic_class_pool< T >:

Inheritance graph
[legend]
Collaboration diagram for atomic_class_pool< T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class T>
struct atomic_class_pool< T >

A thread-safe memory pool for typed objects, based on atomic_preallocated_pool.

Provides a replacement for new/delete on the specific class. Note that there's actually no way to prevent the user from allocating whatever they want, but they will be unable to destroy anything but the specified class (and its subclasses).

 Example:

        class foo { };
        atomic_class_pool<foo> pool;
        foo* f = new(pool) foo;
        pool.destroy(f);

Definition at line 112 of file atomic_class_pool.h.

Public Member Functions

 atomic_class_pool (long nbytes=sizeof(T), long seed=128)
 Create a pool for class T.
void destroy (T *tptr)
 Destroys an object (by calling its destructor) and returns its memory to the pool.
int nbytes ()
 Return the object size given to the constructor.

Friends

void * operator new (size_t, atomic_class_pool< T > &)
 WARNING: When finished, call pool.destroy(t) instead of delete.
void operator delete (void *, atomic_class_pool< T > &)


Constructor & Destructor Documentation

template<class T>
atomic_class_pool< T >::atomic_class_pool ( long  nbytes = sizeof(T),
long  seed = 128 
) [inline]

Create a pool for class T.

By default the pool will hand out sizeof(T) bytes at a time; if T is a base class and this pool is to be used with subclasses, nbytes must be set at least as large as the largest class. Oversized allocations will assert().

Definition at line 121 of file atomic_class_pool.h.


Member Function Documentation

template<class T>
void atomic_class_pool< T >::destroy ( T *  tptr  )  [inline]

Destroys an object (by calling its destructor) and returns its memory to the pool.

Undefined behavior results if the object did not come from this pool.

Definition at line 132 of file atomic_class_pool.h.

References atomic_preallocated_pool::dealloc().

Here is the call graph for this function:


Friends And Related Function Documentation

template<class T>
void* operator new ( size_t  nbytes,
atomic_class_pool< T > &  pool 
) [friend]

WARNING: When finished, call pool.destroy(t) instead of delete.

NOTE: use placement-style new with the pool.

 usage: T* t = new(pool) T(...)

template<class T>
void operator delete ( void *  ptr,
atomic_class_pool< T > &  pool 
) [friend]

Called automatically by the compiler if T's constructor throws (otherwise memory would leak).

Unfortunately, there is no "delete(pool)" syntax in C++ so the user must still call pool.destroy()


The documentation for this struct was generated from the following file:
Generated on Wed Jul 7 17:22:42 2010 for Shore Storage Manager by  doxygen 1.4.7