manual memory management

David Nadlinger see at klickverbot.at
Mon Jan 7 07:25:44 PST 2013


On Monday, 7 January 2013 at 15:01:27 UTC, Gor Gyolchanyan wrote:
> How can I have an associative array, which uses a custom 
> allocator?

I'm afraid the only viable solution right now is to implement 
your own AA type as a struct with overloaded operators (which is 
in fact what the built-in AAs are lowered to as well).

There are two downside to this, though - besides, of course, the 
fact that you need a custom implementation:
  - You cannot pass your type to library functions expecting a 
built-in associative array.
  - You lose the convenient literal syntax. This could be fixed in 
the language, though, by providing a rewrite to a variadic 
constructor of user types for array/AA literals, thus eliminating 
the need for GC allocations (gah, another thing I just need to 
find the time to write up a DIP for…).

David


More information about the Digitalmars-d mailing list