58#ifndef LIB_ALLOCATION_CLUSTER_H
59#define LIB_ALLOCATION_CLUSTER_H
71 namespace test {
class AllocationCluster_test; }
101 allot (
size_t bytes,
size_t alignment)
103 void* loc = std::align (alignment, bytes,
pos,
rest);
133 template<class TY, typename...ARGS>
136 template<class TY, typename...ARGS>
145 [[nodiscard]] X*
allocate (
size_t n) {
return mother_->allot<X>(n); }
163 bool canAdjust (
void* loc,
size_t oldSiz,
size_t newSiz)
const;
164 void doAdjust (
void* loc,
size_t oldSiz,
size_t newSiz);
185 return static_cast<X*
> (
allotMemory (cnt *
sizeof(X),
alignof(X)));
206 template<
typename...ARGS>
236 size_t ADMIN_OVERHEAD = 2 *
sizeof(
void*);
244 template<
class TY,
typename...ARGS>
248 return *
new(allot<TY>()) TY (std::forward<ARGS> (args)...);
256 template<
class TY,
typename...ARGS>
260 if constexpr (std::is_trivial_v<TY>)
261 return createDisposable<TY> (std::forward<ARGS> (args)...);
264 auto& frame = createDisposable<Frame> (std::forward<ARGS> (args)...);
266 return frame.payload;
286 throw err::Invalid {
"AllocationCluster: unable to perform this allocation adjustment."};
293 int offset{int(newSiz) - int(oldSiz)};
310 return offset <= int(rest);
316 return loc ==
static_cast<std::byte const*
> (pos) - siz;
328 template<
class I,
class E,
template<
typename>
class ALO>
331 template<
template<
typename>
class ALO,
typename...ARGS>
350 using Adapter = AllocationCluster::template Allocator<X>;
352 template<
class I,
class E>
360 size_t static constexpr ALLOC_LIMIT = AllocationCluster::max_size();
370 if (not bucket)
return false;
371 size_t currSize = bucket->getAllocSize();
372 long delta = long(request) - long(bucket->buffSiz);
373 return this->mother_->canAdjust (bucket,currSize, currSize+delta);
379 size_t request = cnt*spread;
381 if (not canExpand (bucket,request))
382 return Base::realloc (bucket,cnt,spread);
384 size_t currSize = bucket->getAllocSize();
385 size_t delta = request - bucket->buffSiz;
386 this->mother_->doAdjust (bucket, currSize, currSize+delta);
387 bucket->buffSiz += delta;
388 ENSURE (bucket->buffSiz == request);
virtual ~Destructor()
this is an interface
An overlay view for the AllocationCluster to add functionality for adding / clearing extents and regi...
A pile of objects sharing common allocation and lifecycle.
~AllocationCluster() noexcept
The shutdown of an AllocationCluster walks all extents and invokes all registered deleter functions a...
void expandStorage(size_t)
Expand the alloted storage pool by a block, suitable to accommodate at least the indicated request.
void __enforce_limits(size_t, size_t)
Allocation cluster uses a comparatively small tile size for its extents, which turns out to be a freq...
void * allotMemory(size_t bytes, size_t alignment)
portion out the requested amount of memory, possibly claiming a new pool block.
static constexpr size_t EXTENT_SIZ
hard wired size of storage extents
void doAdjust(void *loc, size_t oldSiz, size_t newSiz)
Adjust the size of the latest raw memory allocation dynamically.
AllocationCluster()
Prepare a new clustered allocation to be expanded by extents of size EXTENT_SIZ, yet discarded all at...
bool canAdjust(void *loc, size_t oldSiz, size_t newSiz) const
void registerDestructor(Destructor &)
size_t numExtents() const
TY & createDisposable(ARGS &&...)
Allocator< X > getAllocator()
static constexpr size_t max_size()
Maximum individual allocation size that can be handled.
Derived specific exceptions within Lumiera's exception hierarchy.
Types marked with this mix-in may be moved but not copied.
Any copy and copy construction prohibited.
Lumiera error handling (C++ interface).
AllocationCluster::template Allocator< X > Adapter
Extension point: how to configure the SeveralBuilder to use an allocator ALO, initialised by ARGS.
Implementation namespace for support and library code.
bool operator==(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
Supporting equality comparisons...
Test runner and basic definitions for tests.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
AllocationWithDestructor(ARGS &&...args)
AllocationCluster * mother_
void deallocate(X *, size_t) noexcept
Allocator(AllocationCluster *m)
Allocator(Allocator< T > const &o)
maintaining the Allocation
bool hasReserve(int offset) const
bool matches_last_allocation(void const *loc, size_t siz) const
void adjustPos(int offset)
void * allot(size_t bytes, size_t alignment)
Policy Mix-In used to adapt to the ElementFactory and Allocator.
Policy(AllocationCluster &clu)
bool canExpand(Bucket *bucket, size_t request)
Bucket * realloc(Bucket *bucket, size_t cnt, size_t spread)