RawAutoalignedBuff

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.

@trusted
struct RawAutoalignedBuff (
size_t alignment
size_t maxBytes
) {}

Alias This

buff

Members

Functions

initialize
void initialize(size_t bytes, bool zeroFill)

Initializes the struct.

Properties

buff
void[] buff [@property getter]

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

Examples

t
{
	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]

Meta