Lumiera  0.pre.03
»edit your freedom«
allocation-cluster.hpp File Reference

Go to the source code of this file.

Description

Memory management for the low-level model (render nodes network).

The model is organised into temporal segments, which are considered to be structurally constant and uniform. The objects within each segment are strongly interconnected, and thus each segment is created within a single build process and is replaced or released as a whole. AllocationCluster implements memory management to support this usage pattern. Optionally it is even possible to skip invocation of object destructors, making de-allocation highly efficient (typically the memory pages are already cache-cold when about to discarded).

base allocation
The actual allocation of storage extents uses heap memory expanded in blocks of AllocationCluster::EXTENT_SIZ. While the idea is to perform allocations mostly at start and then hold and use the memory, the allocation is never actually closed — implying that further allocations can be added during the whole life time, which may possibly even trigger a further base allocation if storage space in the last Extent is exhausted. In theory, it would be possible to use a custom allocation (in the AllocationCluster::StorageManager::Extents, which is a lib::LinkedElements and could be parametrised with a allocator template). Allocations are never discarded, and thus any alloted memory will be kept until the whole AllocationCluster is destroyed as a compound.
using as STL allocator
AllocationCluster::Allocator is an adapter to expose the interface expected by std::allocator_traits (and thus usable by all standard compliant containers). With this usage, the container manages the contained objects, including the invocation of their destructors, while relying on the allocator to allot and discard bare memory. However, to avoid invoking any destructors, the container itself can be created with AllocationCluster::createDisposable. This causes the container (front-end) to be emplaced itself into the used AllocationCluster — and since the container's destructor will not be invoked in this arrangement, the container will not be able to invoke element dtors.
dynamic adjustments
Under controlled conditions, it is possible to change the size of the latest raw allocation handed out, within the limits of the available reserve in the current memory extent. Obviously, this is a dangerous low-level feature, yet offers some flexibility for containers and allocation schemes built on top.
Warning
deliberately not threadsafe.
Remarks
confine usage to a single thread or use thread-local clusters.
See also
allocation-cluster-test.cpp
builder::ToolFactory
linked-elements.hpp

Definition in file allocation-cluster.hpp.

#include "lib/error.hpp"
#include "lib/nocopy.hpp"
#include <type_traits>
#include <utility>
#include <memory>

Classes

class  AllocationCluster
 A pile of objects sharing common allocation and lifecycle. More...
 
struct  AllocationPolicy< I, E, ALO >
 Policy Mix-In used to adapt to the ElementFactory and Allocator. More...
 
struct  AllocationCluster::AllocationWithDestructor< X >
 
struct  AllocationCluster::Allocator< X >
 
class  AllocationCluster::Destructor
 
struct  SetupSeveral< ALO, ARGS >::Policy< I, E >
 
struct  SetupSeveral< ALO, ARGS >
 Extension point: how to configure the SeveralBuilder to use an allocator ALO, initialised by ARGS. More...
 
struct  SetupSeveral< std::void_t, lib::AllocationCluster & >
 Specialisation to use lib::Several with storage managed by an AllocationCluster instance, which must be provided as argument. More...
 
struct  AllocationCluster::Storage
 maintaining the Allocation More...
 

Namespaces

 lib
 Implementation namespace for support and library code.