Construct an object that will use the provided memory
Total capacity of the block
The same as calling this.removeFrontN(this.length)
Calls ~= to copy the specified _element
Construct a new element after the existing elements
Whether the block has no elements at all
Number of elements the block currently has room for
Current number of elements in the block
Move the specified _element to the back of existing elements
Number of elements in the block
Return a reference to an element
Add an _element after the existing elements; lvalues are copied, rvalues are moved.
A slice providing access _to the specified elements
A slice to all elements; the same as [0..$]
Pointer to the beginning of the block
Remove elements from the head of the block. If n == length, freeCapacity will be equal to capacity after this call. Whether the destructors are called on the removed elements is determined by the dtors template parameter.
String representation of this object mostly for debugging
the type of the elements that will be stored on the block
whether to execute destructors of elements upon removing them
// Constructing a block on a piece of memory ubyte[100] buffer; auto b = ReusableBlock!int(buffer); // Depending on the alignment of the elements, the capacity may be less than // then requested amount assert(b.capacity <= buffer.length / int.sizeof); // Add 2 elements b ~= 0; b ~= 1; b.length.shouldBe(2); b[0].shouldBe(0); b[1].shouldBe(1); b.freeCapacity.shouldBe(b.capacity - 2); // Remove the first one b.removeFrontN(1); b.length.shouldBe(1); b[0].shouldBe(1); // Note that free capacity does not increase: b.freeCapacity.shouldBe(b.capacity - 2); // Remove all elements and reset the block b.clear(); b.length.shouldBe(0); // This time all capacity is free b.freeCapacity.shouldBe(b.capacity);
A reusable memory block for placing objects on.
The elements are added only at the back either by copying or by moving. They are removed only from the front. The elements are never moved to a different memory location inside the buffer.