Loki
0.1.7
|
#include <SmallObj.h>
Public Types | |
typedef AllocatorSingleton< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy > | ObjAllocatorSingleton |
Static Public Member Functions | |
static void * | operator new (std::size_t size) throw ( std::bad_alloc ) |
Throwing single-object new throws bad_alloc when allocation fails. | |
static void * | operator new (std::size_t size, const std::nothrow_t &) throw () |
Non-throwing single-object new returns NULL if allocation fails. | |
static void * | operator new (std::size_t size, void *place) |
Placement single-object new merely calls global placement new. | |
static void | operator delete (void *p, std::size_t size) throw () |
Single-object delete. | |
static void | operator delete (void *p, const std::nothrow_t &) throw () |
static void | operator delete (void *p, void *place) |
Placement single-object delete merely calls global placement delete. | |
Base class for small object allocation classes. The shared implementation of the new and delete operators are here instead of being duplicated in both SmallObject or SmallValueObject, later just called Small-Objects. This class is not meant to be used directly by clients, or derived from by clients. Class has no data members so compilers can use Empty-Base-Optimization.
The SmallObjectBase template needs a lifetime policy because it owns a singleton of SmallObjAllocator which does all the low level functions. When using a Small-Object in combination with the SingletonHolder template you have to choose two lifetimes, that of the Small-Object and that of the singleton. The rule is: The Small-Object lifetime must be greater than the lifetime of the singleton hosting the Small-Object. Violating this rule results in a crash on exit, because the hosting singleton tries to delete the Small-Object which is then already destroyed.
The lifetime policies recommended for use with Small-Objects hosted by a SingletonHolder template are
The default lifetime of Small-Objects is LongevityLifetime::DieAsSmallObjectParent to insure that memory is not released before a object with the lifetime LongevityLifetime::DieAsSmallObjectChild using that memory is destroyed. The LongevityLifetime::DieAsSmallObjectParent lifetime has the highest possible value of a SetLongevity lifetime, so you can use it in combination with your own lifetime not having also the highest possible value.
The DefaultLifetime and PhoenixSingleton policies are not recommended since they can cause the allocator to be destroyed and release memory for singletons hosting a object which inherit from either SmallObject or SmallValueObject.
You should not use NoDestroy for the singleton, and then use SingletonWithLongevity for the Small-Object.
typedef AllocatorSingleton< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy > Loki::SmallObjectBase< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy, MutexPolicy >::ObjAllocatorSingleton |
Defines type of allocator singleton, must be public to handle singleton lifetime dependencies.
|
inlinestatic |
Non-throwing single-object delete is only called when nothrow new operator is used, and the constructor throws an exception.