Associative array

Steven Schveighoffer schveiguy at gmail.com
Sun Oct 15 22:16:43 UTC 2023


On 10/14/23 4:46 PM, Nick Treleaven wrote:
> On Friday, 13 October 2023 at 11:32:29 UTC, Imperatorn wrote:
>> Hello there.
>>
>> I'm wondering if anyone would be opposed to us/me making associative 
>> array having resize/reserve public?
>>
>> Currently there exists private members in druntime etc for this but 
>> they are not exposed.
>>
>> Basically I would like to be able to reserve n buckets before populating.
> 
> There was a PR for that but it wasn't merged. It only reserved bucket 
> space, not space for elements. See:
> https://github.com/dlang/druntime/pull/1929#issuecomment-336799304
> 
> 

Yeah, as identified by Andrei (and myself), reserving for an AA means 
reserving elements, not just buckets.

It does not help to compare to other languages, because D's semantic 
requirements for AAs require that you can keep a reference to an element 
long after the AA is gone and deallocated (C++ says as soon as you 
remove an element, all pointers to it are invalid).

The choices are bleak, especially without help from the GC. It's doable, 
but requires some mechanism that doesn't yet exist. I identified the 
options here: https://issues.dlang.org/show_bug.cgi?id=17881

-Steve


More information about the Digitalmars-d mailing list