![]() |
Lumiera 0.pre.04
»edit your freedom«
|
#include "lib/allocation-cluster.hpp"
A pile of objects sharing common allocation and lifecycle.
AllocationCluster owns a heterogeneous collection of objects of various types. Typically, allocation happens during a short time span when building a new segment, and objects are used together until the segment is discarded. The primary leverage is to bulk-allocate memory, and to avoid invoking destructors (and thus to access a lot of cache-cold memory pages on clean-up). A Stdlib compliant #Allocator is provided for use with STL containers. The actual allocation uses heap memory in extents of hard-wired size, maintained by the accompanying StorageManager.
Definition at line 87 of file allocation-cluster.hpp.
Classes | |
| struct | AllocationWithDestructor |
| struct | Allocator |
| class | Destructor |
| struct | Storage |
| maintaining the Allocation More... | |
| class | StorageManager |
| An overlay view for the AllocationCluster to add functionality for adding / clearing extents and registering optional deleter functions. More... | |
Static Public Attributes | |
| static constexpr size_t | EXTENT_SIZ = 256 |
| hard wired size of storage extents | |
Static Public Member Functions | |
| static constexpr size_t | max_size () |
| Maximum individual allocation size that can be handled. | |
Public Member Functions | |
| AllocationCluster () | |
| Prepare a new clustered allocation to be expanded by extents of size EXTENT_SIZ, yet discarded all at once when the dtor is called. | |
| ~AllocationCluster () noexcept | |
| The shutdown of an AllocationCluster walks all extents and invokes all registered deleter functions and then discards the complete storage. | |
| size_t | numExtents () const |
| size_t | numBytes () const |
| template<class TY , typename... ARGS> | |
| TY & | create (ARGS &&...) |
| template<class TY , typename... ARGS> | |
| TY & | createDisposable (ARGS &&...) |
| template<typename X > | |
| Allocator< X > | getAllocator () |
| bool | canAdjust (void *loc, size_t oldSiz, size_t newSiz) const |
| void | doAdjust (void *loc, size_t oldSiz, size_t newSiz) |
| Adjust the size of the latest raw memory allocation dynamically. | |
| template<class TY , typename... ARGS> | |
| TY & | createDisposable (ARGS &&...args) |
| Factory function: place a new instance into this AllocationCluster, but without invoking its destructor on clean-up (for performance reasons). | |
| template<class TY , typename... ARGS> | |
| TY & | create (ARGS &&...args) |
| Factory function: place a new instance into this AllocationCluster; the object will be properly destroyed when the cluster goes out of scope. | |
Friends | |
| class | test::AllocationCluster_test |
Private Member Functions | |
| void * | allotMemory (size_t bytes, size_t alignment) |
| portion out the requested amount of memory, possibly claiming a new pool block. | |
| template<typename X > | |
| X * | allot (size_t cnt=1) |
| void | expandStorage (size_t) |
| Expand the alloted storage pool by a block, suitable to accommodate at least the indicated request. | |
| void | registerDestructor (Destructor &) |
| void | __enforce_limits (size_t, size_t) |
| Allocation cluster uses a comparatively small tile size for its extents, which turns out to be a frequently encountered limitation in practice. | |
Private Member Functions inherited from MoveOnly | |
| ~MoveOnly ()=default | |
| MoveOnly ()=default | |
| MoveOnly (MoveOnly &&)=default | |
| MoveOnly (MoveOnly const &)=delete | |
| MoveOnly & | operator= (MoveOnly &&)=delete |
| MoveOnly & | operator= (MoveOnly const &)=delete |
Private Attributes | |
| Storage | storage_ |
Prepare a new clustered allocation to be expanded by extents of size EXTENT_SIZ, yet discarded all at once when the dtor is called.
The constructor does not allocate anything immediately.
Definition at line 207 of file allocation-cluster.cpp.
|
noexcept |
The shutdown of an AllocationCluster walks all extents and invokes all registered deleter functions and then discards the complete storage.
Definition at line 220 of file allocation-cluster.cpp.
References AllocationCluster::StorageManager::access(), and AllocationCluster::StorageManager::discardAll().
Here is the call graph for this function:
|
staticconstexpr |
Maximum individual allocation size that can be handled.
Definition at line 234 of file allocation-cluster.hpp.
References AllocationCluster::EXTENT_SIZ.
Referenced by AllocationCluster::__enforce_limits(), AllocationCluster::StorageManager::calcAllocInCurrentBlock(), SeveralBuilder_test::check_CustomAllocator(), AllocationCluster::expandStorage(), AllocationCluster::numBytes(), and AllocationCluster::StorageManager::prependNextBlock().
Here is the caller graph for this function:| size_t numExtents | ( | ) | const |
Definition at line 285 of file allocation-cluster.cpp.
References AllocationCluster::StorageManager::access(), and AllocationCluster::StorageManager::determineExtentCnt().
Referenced by SeveralBuilder_test::check_CustomAllocator(), AllocationCluster_test::checkLifecycle(), AllocationCluster_test::dynamicAdjustment(), AllocationCluster::numBytes(), AllocationCluster_test::simpleUsage(), AllocationCluster_test::use_as_Allocator(), and AllocationCluster_test::verifyInternals().
Here is the call graph for this function:
Here is the caller graph for this function:| size_t numBytes | ( | ) | const |
Definition at line 296 of file allocation-cluster.cpp.
References AllocationCluster::StorageManager::access(), AllocationCluster::StorageManager::calcAllocInCurrentBlock(), AllocationCluster::max_size(), and AllocationCluster::numExtents().
Referenced by SeveralBuilder_test::check_CustomAllocator(), AllocationCluster_test::dynamicAdjustment(), LinkedElements_test::verify_customAllocator(), and AllocationCluster_test::verifyInternals().
Here is the call graph for this function:
Here is the caller graph for this function:| TY & create | ( | ARGS && | ... | ) |
Referenced by SeveralBuilder_test::check_CustomAllocator(), LinkedElements_test::UseAllocationCluster::create(), AllocationCluster_test::dynamicAdjustment(), lib::test::anonymous_namespace{allocation-cluster-test.cpp}::place_object(), AllocationCluster_test::simpleUsage(), and AllocationCluster_test::verifyInternals().
Here is the caller graph for this function:| TY & createDisposable | ( | ARGS && | ... | ) |
Referenced by AllocationCluster_test::checkLifecycle(), and AllocationCluster_test::verifyInternals().
Here is the caller graph for this function:
|
inline |
Definition at line 160 of file allocation-cluster.hpp.
Referenced by AllocationCluster_test::use_as_Allocator(), and LinkedElements_test::verify_customAllocator().
Here is the caller graph for this function:
|
inline |
Definition at line 291 of file allocation-cluster.hpp.
References AllocationCluster::Storage::hasReserve(), AllocationCluster::Storage::matches_last_allocation(), and AllocationCluster::storage_.
Referenced by AllocationCluster::doAdjust(), and AllocationCluster_test::dynamicAdjustment().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Adjust the size of the latest raw memory allocation dynamically.
| loc | an allocation provided by this AllocationCluster |
| oldSiz | the size requested for the allocation loc |
| newSiz | desired new size for this allocation |
Definition at line 283 of file allocation-cluster.hpp.
References AllocationCluster::Storage::adjustPos(), AllocationCluster::canAdjust(), and AllocationCluster::storage_.
Referenced by AllocationCluster_test::dynamicAdjustment().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlineprivate |
portion out the requested amount of memory, possibly claiming a new pool block.
Definition at line 172 of file allocation-cluster.hpp.
References AllocationCluster::__enforce_limits(), AllocationCluster::Storage::allot(), AllocationCluster::allotMemory(), AllocationCluster::expandStorage(), and AllocationCluster::storage_.
Referenced by AllocationCluster::allot(), and AllocationCluster::allotMemory().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlineprivate |
Definition at line 183 of file allocation-cluster.hpp.
References AllocationCluster::allotMemory().
Here is the call graph for this function:
|
private |
Expand the alloted storage pool by a block, suitable to accommodate at least the indicated request.
Definition at line 241 of file allocation-cluster.cpp.
References AllocationCluster::StorageManager::access(), AllocationCluster::StorageManager::addBlock(), and AllocationCluster::max_size().
Referenced by AllocationCluster::allotMemory().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 249 of file allocation-cluster.cpp.
References AllocationCluster::StorageManager::access(), and AllocationCluster::StorageManager::attach().
Referenced by AllocationCluster::create().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Allocation cluster uses a comparatively small tile size for its extents, which turns out to be a frequently encountered limitation in practice.
This was deemed acceptable, due to its orientation towards performance.
| err::Fatal | when a desired allocation can not be accommodated |
Definition at line 263 of file allocation-cluster.cpp.
References LERR_, and AllocationCluster::max_size().
Referenced by AllocationCluster::allotMemory().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Factory function: place a new instance into this AllocationCluster, but without invoking its destructor on clean-up (for performance reasons).
Definition at line 246 of file allocation-cluster.hpp.
|
inline |
Factory function: place a new instance into this AllocationCluster; the object will be properly destroyed when the cluster goes out of scope.
Definition at line 258 of file allocation-cluster.hpp.
References AllocationCluster::registerDestructor().
Here is the call graph for this function:
|
private |
Definition at line 116 of file allocation-cluster.hpp.
Referenced by AllocationCluster::allotMemory(), AllocationCluster::canAdjust(), AllocationCluster::doAdjust(), and AllocationCluster_test::verifyInternals().
|
staticconstexpr |
hard wired size of storage extents
Definition at line 124 of file allocation-cluster.hpp.
Referenced by AllocationCluster::StorageManager::getCurrentBlockStart(), and AllocationCluster::max_size().
|
friend |
Definition at line 216 of file allocation-cluster.hpp.
Inheritance diagram for AllocationCluster:
Collaboration diagram for AllocationCluster: