www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Creating dynamic arrays of known size

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
Mar 08 2012