Associate information with a pointer address.
bachmeier
no at spam.net
Fri Sep 29 15:41:18 UTC 2023
On Friday, 29 September 2023 at 14:31:54 UTC, BoQsc wrote:
> After being very happy about associative arrays of D Language,
> I encountered that they are not `@nogc`friendly. Unsure if I
> should wait for D language to support it, or do I need to
> rethink everything.
You can work with AA's inside @nogc functions just fine as long
as you don't do something that would cause a GC allocation.
Consider this program:
```
import std;
@nogc double getValue(double[string] aa, string key) {
return aa[key];
}
void main() {
double[string] aa;
aa["one"] = 1.0;
aa["two"] = 2.0;
writeln(aa.getValue("two"));
}
```
I'm not sure why you want to add elements inside a @nogc function
- hard to say without knowing your use case. When I create an AA
with many elements, I disable the GC, add a bunch of elements,
and then turn it back on. Once the AA has been created, I can
send it to @nogc functions for processing. I have a hard time
believing there would be meaningful performance benefits doing
anything further. (Though I can only speak to my experience,
which of course does not include all applications.)
More information about the Digitalmars-d-learn
mailing list