Does associative array change the location of values?

Stanislav Blinov stanislav.blinov at
Sat Oct 30 21:20:15 UTC 2021

On Saturday, 30 October 2021 at 20:19:58 UTC, Imperatorn wrote:

> What test could be written to verify the behaviour?

Assuming the GC was moving?

You'd need a loop allocating different sizes, storing the 
addresses somewhere the GC won't see (i.e. in memory allocated 
not with the GC: malloc, VirtualAlloc, mmap...), orphaning some 
allocations, repeating a bunch of times, and then comparing 
addresses of remaining allocations with stored ones.

Behavior would very much depend on the GC implementation, so 
would a concrete test. Point is, it's allowed to move so we have 
to assume it would even if it doesn't, and relying on it not 
moving (i.e. depending on concrete addresses) is UB.

More information about the Digitalmars-d-learn mailing list