Inheritance diagram for atomic_class_pool< T >:
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. | |
uint | 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 > &) |
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.
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:
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(...)
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()