I want my Memory back ;-)

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jul 13 13:48:04 PDT 2010


On 07/13/2010 03:36 PM, bearophile wrote:
> FeepingCreature:
>> On 13.07.2010 12:28, ABothe wrote:
>>> So there isn't any other method than calling C's free(); or malloc
>>> (); ?
>>
>> That's how it is.
>
> But you can build some abstraction by yourself, for example inside a struct you can keep the pointer to a memory block in the C heap, and in the ~this() of the struct you can put the free(). Then D has to give you a way to disallow the "new" on this struct, to be sure its destructor is called when it goes out of scope (or the object it's contained into gets deallocated).
>
> Bye,
> bearophile

Also refer to RefCounted:

http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/typecons.d#L1991

Highly recommended.


Andrei


More information about the Digitalmars-d mailing list