Creating dynamic arrays of known size
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Mar 8 21:13:13 PST 2012
So, I'm plodding along with my AA implementation that *hopefully* will
eventually reach the point where it's usable enough to be dropped into
druntime. I'm writing .keys and .values right now, and wondering what's
the best way to construct the returned array.
Obviously, using =~ repeatedly is a bad idea, since we already know the
resulting array size. Would this be the best way to do it?
Key[] keys;
keys.length = num_keys;
for (size_t i=0; i < num_keys; i++) {
keys[i] = ...;
}
Looking at aaA.d, I see that _aaKeys calls gc_malloc directly and sets
BlkAttr.NO_SCAN. Should I just copy this code?
T
--
It's bad luck to be superstitious. -- YHL
More information about the Digitalmars-d
mailing list