Loki::SmallObjectBase< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy > Class Template Reference
[Small objects]
#include <SmallObj.h>
Inheritance diagram for Loki::SmallObjectBase< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy >:
[legend]List of all members.
|
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.
|
Detailed Description
template<template< class > class ThreadingModel, std::size_t chunkSize, std::size_t maxSmallObjectSize, std::size_t objectAlignSize, template< class > class LifetimePolicy>
class Loki::SmallObjectBase< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy >
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.
- Lifetime Policy
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.
- Lifetime usage
- Both Small-Object and Singleton use SingletonWithLongevity policy. The longevity level for the singleton must be lower than that for the Small-Object. This is why the AllocatorSingleton's GetLongevity function returns the highest value.
- FollowIntoDeath lifetime: The Small-Object has FollowIntoDeath::With<LIFETIME>::AsMasterLiftime policy and the Singleton has FollowIntoDeath::AfterMaster<MASTERSINGLETON>::IsDestroyed policy, where you could choose the LIFETIME.
- Both Small-Object and Singleton use NoDestroy policy. Since neither is ever destroyed, the destruction order does not matter. Note: yow will get memory leaks!
You should *not* use NoDestroy for the singleton, and then use SingletonWithLongevity for the Small-Object.
- Examples:
- test/SmallObj/SmallSingleton.cpp
- test/Singleton/Dependencies.cpp
Member Typedef Documentation
template<template< class > class ThreadingModel, std::size_t chunkSize, std::size_t maxSmallObjectSize, std::size_t objectAlignSize, template< class > class LifetimePolicy> |
typedef AllocatorSingleton< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy > Loki::SmallObjectBase< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy >::ObjAllocatorSingleton |
|
|
Defines type of allocator singleton, must be public to handle singleton lifetime dependencies. |
Member Function Documentation
template<template< class > class ThreadingModel, std::size_t chunkSize, std::size_t maxSmallObjectSize, std::size_t objectAlignSize, template< class > class LifetimePolicy> |
static void Loki::SmallObjectBase< ThreadingModel, chunkSize, maxSmallObjectSize, objectAlignSize, LifetimePolicy >::operator delete |
( |
void * |
p, |
|
|
const std::nothrow_t & |
|
|
) |
throw () [inline, static] |
|
|
Non-throwing single-object delete is only called when nothrow new operator is used, and the constructor throws an exception. |
The documentation for this class was generated from the following file:
Generated on Mon Jan 9 09:34:38 2006 for Loki by
1.4.5