On Tue, 29 Mar 2011 18:42:59 -0400, bearophile <[email protected]>
wrote:
Piotr Szturmaj:
void[0][string] aa;
aa["key"] = [];
assert("key" in aa);
Nice. I have done a benchmark, and it seems a void[0][int] uses the same
amount of memory as a int[int]. I have not tried a void[0][string].
Each node in the hash has a pointer (for the next node), a hash (size_t)
and the key and value. Given the granularity of allocation (16 bytes),
anything less than 16 bytes will be 16 bytes.
If the above trick works correctly, a void[0][string] should be the same
size as int[int]. (8 bytes for pointer and hash, 8 bytes for string key,
and hopefully 0 bytes for the value).
BTW, you should not use [] in your code, as this calls a runtime array
allocation function. Better to use something else, not sure what though.
Maybe an enum?
-Steve