How to make AA key a pointer
Clinton
clinton.d.skakun at gmail.com
Mon Feb 19 14:55:01 UTC 2018
Hi all, I need advice from better developers on this concern.
I'm using an AA to reference another array for quicker access:
[code]
alias contactId = string;
bool[contactId][] matches;
ulong[contactId] idsToMatches;
bool[string] matchesForId(string id) {
return matches.get(idsToMatches[id], bool[string].init);
}
[/code]
Just wondering, how do I set the keys to avoid copying the id
string? So, let's say ids come from another array of structs(e.g.
Contact[]). I want to avoid having two copies of the string id
value in both of these AAs above (to avoid using extra memory
usage).
The reason this is a potential issue is because these arrays can
get extremely large. This is to match duplicate contacts and
group them in matches. The reason I use bool is because it's the
smallest size type and I don't think I can use void.
I guess my question is: does dmd already create pointers to the
id from the AA, or is each new key a new allocation?
More information about the Digitalmars-d-learn
mailing list