Empty associative array
Mike Parker
aldacron at gmail.com
Mon Aug 9 12:46:19 UTC 2021
On Monday, 9 August 2021 at 12:16:44 UTC, deadalnix wrote:
>
> I find myself in a situation where I use an AA to cache some
> computation results, and this cache might be necessary in a
> couple of places in the application. It works great, unless the
> cache is initially empty, in which case, every location ends up
> with its own cache, defeating the whole point of caching these
> results to begin with.
Do you mean you're passing the AA to those locations as a
function parameter? In that case, it's no different from the
behavior of dynamic arrays. The AA handle itself is not a
reference, so you need to explicitly pass it by reference:
```d
void func(ref int[int] aa) { aa[3] = 3; }
void main()
{
int[int] aa;
func(aa);
assert(aa[3] == 10);
}
```
More information about the Digitalmars-d
mailing list