assumeSafeAppend on slice of static array?
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Tue Apr 22 11:10:30 PDT 2014
I'm going through some code and thinking of ways to reduce GC pressure,
and came across a bit that needed to append some items to an array:
T[] args;
lex.expect("(");
args ~= parseSingleItem(lex);
while (!lex.empty) {
lex.expect(",");
args ~= parseSingleItem(lex);
}
lex.expect(")");
return computeResult(args);
Now obviously, in the general case (with arbitrarily many number of
items) some GC allocations will be needed, but the most common use-cases
are actually only 1 or 2 items each time. Allocating lots of small
arrays seem to be rather wasteful, so I thought to use a static array as
a buffer instead.
The question is, is there a way to take a slice of the static array, set
the length to zero, and append to it with ~= such that when it runs out
of space in the static buffer, it will reallocate a longer array on the
GC heap? Or is this a bad idea?
T
--
Without geometry, life would be pointless. -- VS
More information about the Digitalmars-d
mailing list