custom memory management

Steven Schveighoffer schveiguy at yahoo.com
Thu Feb 27 14:15:40 PST 2014


On Thu, 27 Feb 2014 16:46:15 -0500, Simon Bürger  
<simon.buerger at rwth-aachen.de> wrote:

> I know the suggested way in D is to not deallocate the buffer at all,  
> but rely on the gc to collect it eventually. But it still puzzles me  
> that it seems to be impossible to do. Anybody have an idea how I could  
> make it work?

Unfortunately, nothing is foolproof. The most "correct" solution is likely  
to use malloc/free. Yes, if you just new one of these, you will have to  
destroy it.

But if you have a destructor that uses GC allocated memory such an object  
can NEVER be a member of a heap-allocated class.

More and more, I think a thread-local flag of "I'm in the GC collection  
cycle" would be hugely advantageous -- if it doesn't already exist...

-Steve


More information about the Digitalmars-d-learn mailing list