Constructs a region backed by a user-provided store.
Alignment offered.
Allocates n bytes of memory aligned at alignment a.
Allocates n bytes of memory. The shortest path involves an alignment adjustment (if alignment > 1), an increment, and a comparison.
Allocates and returns all memory available to this region.
Nonstandard property that returns bytes available for allocation.
Deallocates b. This works only if b was obtained as the last call to allocate; otherwise (i.e. another allocation has occurred since) it does nothing.
Deallocates all memory allocated by this region, which can be subsequently reused for new allocations.
Returns Ternary.yes if no memory has been allocated in this region, Ternary.no otherwise. (Never returns Ternary.unknown.)
Expands an allocated block in place. Expansion will succeed only if the block is the last allocated. Defined only if growDownwards is No.growDownwards.
Rounds the given size to a multiple of the alignment
Queries whether b has been allocated with this region.
import std.typecons : Ternary; ubyte[1024] store; auto myRegion = BorrowedRegion!(1)(store[]); assert(myRegion.empty == Ternary.yes); assert(myRegion.available == store.length); void[] b = myRegion.allocate(101); assert(b.length == 101); assert(myRegion.empty == Ternary.no); assert(myRegion.owns(b) == Ternary.yes); assert(myRegion.available == store.length - b.length); void[] b2 = myRegion.allocate(256); // Can only free the most recent allocation assert(myRegion.deallocate(b) == false); assert(myRegion.deallocate(b2) == true); myRegion.deallocateAll(); assert(myRegion.empty == Ternary.yes);
A BorrowedRegion allocates directly from a user-provided block of memory.
Unlike a Region, a BorrowedRegion does not own the memory it allocates from and will not deallocate that memory upon destruction. Instead, it is the user's responsibility to ensure that the memory is properly disposed of.
In all other respects, a BorrowedRegion behaves exactly like a Region.