FreePOOMA
2.4.1
|
A class that manages a static Pool in which the block size is a template parameter. More...
Classes | |
class | RoundedStaticPool< SP > |
All this does is define alloc and free as static functions, and the static pool itself. More... | |
class | StaticPool< T > |
This is a wrapper class on RoundedStaticPool, which just rounds up its input block size and inherits from RoundedStaticPool. More... |
A class that manages a static Pool in which the block size is a template parameter.
If you just create a Pool as a static object in each of many different pooled classes, you end up with potentially a large number of different pools. In particular, if you pool of expression objects, you will have a different pool for each kind of expression object, which is inefficient because many different expression types will have the same size, and could therefore share a pool.
class StaticPool<S> has a static Pool of size S. Strictly speaking, it has a pool of size S', where S' is rounded up to a multiple of 8 bytes. All the StaticPools that round up to size S' share the same pool.
This is done by having the Pool be static data in a base class RoundedStaticPool<SP>, where SP is S rounded up.
Usage: When you want a chunk of memory for an object of type T, you say:
T* p = StaticPool<sizeof(T)>::alloc()
To free that memory you say:
StaticPool<sizeof(T)>::free(p);