Manual memory management in D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jul 13 15:29:44 PDT 2010


On 07/13/2010 05:10 PM, Nick Sabalausky wrote:
> "Andrei Alexandrescu"<SeeWebsiteForEmail at erdani.org>  wrote in message
> news:i1inhi$2fon$1 at digitalmars.com...
>> On 07/13/2010 04:42 PM, Vladimir Panteleev wrote:
>>> On Wed, 14 Jul 2010 00:33:20 +0300, bearophile
>>> <bearophileHUGS at lycos.com>  wrote:
>>>
>>>> Vladimir Panteleev:
>>>>> ARGHARGHARGH
>>>>
>>>> There is emplace() now. I don't know how much good it currently is.
>>>
>>> I know that I can do this manually in other ways, the problem is that
>>> this creates verbose and unintuitive code.
>>
>> I agree. I think we should, again, define two primitives:
>>
>> T* malloc(T, A...)(A args) if (!is(T == class)&&  !isDynamicArray!T);
>> T malloc(T, A...)(A args) if (is(T == class) || isDynamicArray!T);
>> free(T)(ref T obj);
>>
>> The first two call C's malloc, constructor (if any), and returns the
>> allocated object. The last calls the destructor (if any) and then free().
>>
>> worksforyou?
>>
>
> I think I'm missing something. Instead of regressing back to malloc&  co.,
> why not just have the custom allocators?

Because C++ allocators suck but I never knew exactly why. So... your 
design here.

Andrei


More information about the Digitalmars-d mailing list