StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::Heap Namespace Reference

Allocate and free raw blocks on Base's heap. More...

Classes

struct  ObjectDeleter
 Destroy the concrete object and return its block to Free. More...

Functions

void * Allocate (std::size_t bytes)
 Allocate bytes on Base's heap.
void Free (void *pointer) noexcept
 Release a block obtained from Allocate.
void ThrowExpiredWeakPointer ()
 Throw ExpiredWeakPointerError.
void RethrowException ()
 Preserve an active StormByte exception or translate a foreign one.

Variables

constexpr Size Alignment {16}
 Alignment guaranteed by Allocate, in bytes.

Detailed Description

Allocate and free raw blocks on Base's heap.

Deleter for a caller-owned std::unique_ptr that still frees Base's block.

Public templates call Allocate and Free through matching declarations in the public headers. This header exists only for the translation unit that defines those functions. A failed allocation throws AllocationError and does not allocate the exception message.

Allocation stays in the installed heap header. This name exists so a moved Unique keeps its published deleter type.

Function Documentation

◆ Allocate()

void * StormByte::Safe::Heap::Allocate ( std::size_t bytes)

Allocate bytes on Base's heap.

Parameters
bytesBlock size in octets. Zero is forwarded to operator new.
Returns
Address of the block. Never null. Aligned to Alignment.
Exceptions
AllocationErrorThe allocator cannot satisfy the request. std::bad_alloc is not propagated.
ExceptionA StormByte exception already in flight is rethrown unchanged.
OperationErrorA foreign exception is translated. If that translation cannot allocate, AllocationError is thrown instead.

◆ Free()

void StormByte::Safe::Heap::Free ( void * pointer)
noexcept

Release a block obtained from Allocate.

Parameters
pointerBlock address, or a null pointer. A null pointer is ignored.

◆ RethrowException()

void StormByte::Safe::Heap::RethrowException ( )

Preserve an active StormByte exception or translate a foreign one.

Precondition
Called from an active exception handler.
Exceptions
ExceptionA StormByte exception already in flight is rethrown unchanged.
AllocationErrorThe active exception is std::bad_alloc, or translating it cannot allocate.
OperationErrorThe active exception is foreign. The body is what(), or a fixed unknown-exception text.

◆ ThrowExpiredWeakPointer()

void StormByte::Safe::Heap::ThrowExpiredWeakPointer ( )

Throw ExpiredWeakPointerError.

Exceptions
ExpiredWeakPointerErrorAlways. The body does not include the path.

Variable Documentation

◆ Alignment

Size StormByte::Safe::Heap::Alignment {16}
inlineconstexpr

Alignment guaranteed by Allocate, in bytes.

Matches String Storage (alignas(16)) after the SSO capacity increase. Plain operator new is not reliable for alignof(std::max_align_t) on every musl / libstdc++ combination.