TempAlloc: an unusual request

dsimcha dsimcha at yahoo.com
Mon Jun 20 08:01:32 PDT 2011


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> I do agree with your choice of scan flags because your analysis of
> costs, benefits, and onus put on the user is compelling. In this case,
> however, it seems to me that functions that implicitly return stuff on
> the TempAlloc stack are paving the way towards messed-up modules that
> can't be reasoned about modularly.
> Thanks,
> Andrei

There are two use cases for implicitly returning TempAlloc-allocated memory:

1.  In a private API.

2.  I have a few data structures that I may clean up and submit as a proposal
later (hash table, hash set, AVL tree) whose implementations are specifically
optimized for TempAlloc.  For example, the hash table is provisionally called
StackHash.  I'd really rather write:

auto table = StackHash!(uint, double)(10);
table[666] = 8675309;

rather than:

auto table = StackHash!(uint, double)(10);
table.addElement(666, 8675309, someLongVerboseAllocator);


More information about the Digitalmars-d mailing list