The non allocating D subset
Adam D. Ruppe
destructionator at gmail.com
Sat Jun 1 08:10:59 PDT 2013
huh array literals don't work since they call an allocation
function, even if all the data in them is all static. That's
disappointing.
We can force it though with something like this:
template arrlit(T...) {
static __gshared immutable int[] literal = [T];
alias arrlit = literal;
}
arr2 ~= arrlit!(1,2,3);
then it doesn't allocate (arr2 is a StackArray btw). The
arrlit.ptr is the initialized data segment, which is a much more
reasonable place for it than doing a runtime allocation.
More information about the Digitalmars-d
mailing list