associative array: unexpected results after static initialization

Steven Schveighoffer schveiguy at yahoo.com
Fri Dec 1 16:10:49 UTC 2017


On 12/1/17 11:01 AM, kdevel wrote:
> On Friday, 1 December 2017 at 00:42:00 UTC, H. S. Teoh wrote:
>> Here's the fix:
>>
>>     https://github.com/dlang/druntime/pull/1980
> 
> Great. By the way: It it true, that there cannot be more than 2^32 keys 
> in an associative array (due to the use of uint)?

Yes, and technically even less because there is a requirement to grow 
the array when it's 4/5 full. But such a thing is easily fixed if we 
need to.

Note that due to the way it's currently implemented (and you aren't 
going to get much smaller than this), each key takes 16 bytes (bucket 
ptr + hash) + at least 16 bytes per key/value pair (depending on what's 
stored there).

So you are talking minimum 4GB * 32 = 128GB RAM required if you wanted 
to have such an AA!

-Steve


More information about the Digitalmars-d-learn mailing list