On Monday, 18 May 2015 at 17:14:46 UTC, Steven Schveighoffer wrote:
capacity is analogous to the number of elements in the vector (as returned by array-dimension according to https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node162.html).

arr.length is analogous to the fill pointer.

example:

int[] arr = new int[](5);
assert(arr.capacity > 5);
assert(arr.length == 5);

arr.reserve(100); // expand arr memory block to be able to hold *at least* 100 ints

assert(arr.capacity >= 100);
assert(arr.length == 5);

auto ptr = arr.ptr; // for later assert

arr ~= 1; // increment length by 1, 'fill in' tail of array with '1'

// this should demonstrate how it works
assert(arr.length == 6); // new fill pointer
assert(arr.capacity >= 100); // capacity unchanged
assert(arr.ptr is ptr); // array still lives in same memory block

Apologies for not translating to lisp, I don't know it.

-Steve

Thank you. This is what you need!

Reply via email to