length = 0 clears reserve
Jethro via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 10 18:42:32 PDT 2017
arrays have the ability to reserve but when setting the length to
0, it removes the reserve!! ;/
char[] buf;
buf.reserve = 1000;
buf.length = 0;
assert(buf.capacity == 0);
But I simply want to clear the buffer, not change it's
reserve/capacity.
I've tried to hack by setting the length to 0 through a pointer,
but that still clears the capacity!
I want to do this because I want to be able to reuse the array
without ever reallocating(I'll set the capacity to the max that
will ever be used, I don't have to worry about conflicts since it
will always be ran serially).
It is a bug if dmd is setting the capacity to 0 and reallocating
the array when the length is set to 0. It should either do it
lazily or not at all(or, say setting the length to -1 does not
clear the capacity, only sets the length to 0).
More information about the Digitalmars-d-learn
mailing list