nxt.region_allocator

Members

Functions

alignDownTo
void* alignDownTo(void* ptr, uint alignment)

Aligns a pointer down to a specified alignment. The resulting pointer is less than or equal to the given pointer.

alignUpTo
void* alignUpTo(void* ptr, uint alignment)

Aligns a pointer up to a specified alignment. The resulting pointer is greater than or equal to the given pointer.

alignedAt
bool alignedAt(T* ptr, uint alignment)

Returns true if ptr is aligned at alignment.

roundDownToAlignment
size_t roundDownToAlignment(size_t n, uint alignment)

Returns n rounded down to a multiple of alignment, which must be a power of 2.

roundUpToAlignment
size_t roundUpToAlignment(size_t n, uint alignment)

Returns n rounded up to a multiple of alignment, which must be a power of 2.

roundUpToMultipleOf
size_t roundUpToMultipleOf(size_t s, uint base)

Returns s rounded up to a multiple of base.

Structs

InSituRegion
struct InSituRegion(size_t size, size_t minAlign = platformAlignment)

InSituRegion is a convenient region that carries its storage within itself (in the form of a statically-sized array).

Region
struct Region(ParentAllocator = NullAllocator, uint minAlign = platformAlignment, Flag!"growDownwards" growDownwards = No.growDownwards)

A Region allocator allocates memory straight from one contiguous chunk. There is no deallocation, and once the region is full, allocation requests return null. Therefore, Regions are often used (a) in conjunction with more sophisticated allocators; or (b) for batch-style very fast allocations that deallocate everything at once.

SbrkRegion
struct SbrkRegion(uint minAlign = platformAlignment)

Allocator backed by $(LINK2 https://en.wikipedia.org/wiki/Sbrk, sbrk) for Posix systems. Due to the fact that sbrk is not thread-safe by design, SbrkRegion uses a mutex internally. This implies that uncontrolled calls to brk and sbrk may affect the workings of SbrkRegion adversely.

SharedRegion
struct SharedRegion(ParentAllocator = NullAllocator, uint minAlign = platformAlignment, Flag!"growDownwards" growDownwards = No.growDownwards)

The threadsafe version of the Region allocator. Allocations and deallocations are lock-free based using core.atomic.cas.

Meta