Unstandard

Miscellaneous memory routines.

License
Boost License 1.0.
Authors
Denis Shelomovskij

struct  RawAutoalignedBuff(size_t alignment, size_t maxBytes);

This struct provides a static buffer of maximum size maxBytes which is aligned as requested by alignment.

The whole struct may be misaligned and moved in memory.

Examples
import unstd.math;

alias Buff = RawAutoalignedBuff!(64, 16);

void[1024] sbuff = void;
auto mbuff = cast(Buff*) sbuff.ptr;
mbuff.initialize();

assert(isAligned!64(cast(size_t) mbuff.buff.ptr));
assert(mbuff.buff == [0, 0, 0, 0]);
mbuff.buff[] = [1, 2, 3, 4];

rawCopy(sbuff.ptr, sbuff.ptr + 1, Buff.sizeof);
mbuff = cast(Buff*) (sbuff.ptr + 1);

assert(isAligned!64(cast(size_t) mbuff.buff.ptr)); 
assert(mbuff.buff == [1, 2, 3, 4]);

pure nothrow void  initialize(in size_t bytes = maxBytes, in bool zeroFill = true);

Initializes the struct.

bytes specifies buffer size.

If zeroFill is true the memory will be zero-filled.

Preconditions:
bytes <= maxBytes

pure nothrow void[]  buff();

Returnes the buffer. Moves the buffer in memory if it is misaligned.

Preconditions:
RawAutoalignedBuff is initialized.