Lumiera
0.pre.03
»edit your freedom«
|
#include "lib/allocation-cluster.hpp"
A pile of objects sharing common allocation and lifecycle.
AllocationCluster owns a number of object families of various types. Each of those contains a initially undetermined (but rather large) number of individual objects, which can be expected to be allocated within a short timespan and which are to be released cleanly on destruction of the AllocationCluster. We provide a service creating individual objects with arbitrary ctor parameters.
implement a facility to control the oder in which the object families are to be discarded. Currently they are just purged in reverse order defined by the first request for allocating a certain type.
should we use an per-instance lock? We can't avoid the class-wide lock, unless also the type-ID registration is done on a per-instance base. AllocationCluster is intended to be used within the builder, which executes in a dedicated thread. Thus I doubt lock contention could be a problem and we can avoid using a mutex per instance. Re-evaluate this!
currently all AllocationCluster instances share the same type-IDs. When used within different usage contexts this leads to some slots remaining empty, because not every situation uses any type encountered. wouldn't it be desirable to have multiple distinct contexts, each with its own set of Type-IDs and maybe also separate locking? Is this issue worth the hassle? //////////////////////////////TICKET #169
Definition at line 91 of file allocation-cluster.hpp.
Public Member Functions | |
AllocationCluster () | |
creating a new AllocationCluster prepares a table capable of holding the individual object families to come. More... | |
~AllocationCluster () noexcept | |
On shutdown of the AllocationCluster we need to assure a certain destruction order is maintained by explicitly invoking a cleanup operation on each of the low-level memory manager objects. | |
template<class TY > | |
size_t | count () const |
helper for diagnostics More... | |
template<class TY , typename... ARGS> | |
TY & | create (ARGS &&...args) |
size_t | size () const |
Classes | |
class | MemoryManager |
"Low-level" Memory manager for allocating small objects of a fixed size. More... | |
struct | TypeInfo |
struct | TypeSlot |
organising the association Type -> table entry More... | |
Private Types | |
using | Allo = Allocator_TransferNoncopyable< HMemManager > |
using | HMemManager = ScopedPtrHolder< MemoryManager > |
using | ManagerTable = std::vector< HMemManager, Allo > |
Private Member Functions | |
template<class TY > | |
void * | allocation () |
initiate an allocation for the given type | |
template<class TY > | |
TY & | commit (TY *obj) |
finish the allocation after the ctor is successful | |
size_t | countActiveInstances (size_t &slot) const |
void | finishAlloc (size_t &slot, void *) |
enrol the allocation after successful ctor call | |
HMemManager & | handler (size_t slot) |
HMemManager const & | handler (size_t slot) const |
void * | initiateAlloc (size_t &slot) |
implementation of the actual memory allocation is pushed down to the MemoryManager impl. More... | |
void * | initiateAlloc (TypeInfo type, size_t &slot) |
Private Member Functions inherited from NonCopyable | |
NonCopyable (NonCopyable const &)=delete | |
NonCopyable & | operator= (NonCopyable const &)=delete |
Private Attributes | |
ManagerTable | typeHandlers_ |
table of active MemoryManager instances | |
Static Private Attributes | |
static size_t | maxTypeIDs |
storage for static bookkeeping of type allocation slots | |
creating a new AllocationCluster prepares a table capable of holding the individual object families to come.
Each of those is managed by a separate instance of the low-level memory manager.
Definition at line 189 of file allocation-cluster.cpp.
size_t size | ( | ) | const |
Definition at line 273 of file allocation-cluster.cpp.
References AllocationCluster::MemoryManager::size().
size_t count | ( | ) | const |
helper for diagnostics
Definition at line 276 of file allocation-cluster.hpp.
References AllocationCluster::countActiveInstances().
|
private |
implementation of the actual memory allocation is pushed down to the MemoryManager impl.
Definition at line 229 of file allocation-cluster.cpp.
References AllocationCluster::typeHandlers_.
Referenced by AllocationCluster::allocation().
|
private |
helper for diagnostics, delegating to actual memory manager
Definition at line 287 of file allocation-cluster.cpp.
Referenced by AllocationCluster::count().