Manual memory management in D2
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Jul 13 15:36:20 PDT 2010
On 07/13/2010 05:15 PM, div0 wrote:
> On 13/07/2010 22:58, Andrei Alexandrescu wrote:
>> 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?
>>
>> Andrei
>
> Are they going to register the range with the GC for scanning?
Yah, just like std.container.Array does.
> If so then fine. I do stuff where I've got deterministically allocated
> structs which can wind up having the only live references to other GC
> objects.
>
> Though perhaps we could have 2 different functions, one that registers
> the object with the GC & one without. Being able to easily mix & match
> memory strategies is a great feature so it would be nice to still be
> able to easily do it, even if you make it all library functions with
> great big 'Danger Will Robinson!' stickers all over it.
std.container.Array automatically detects the existence of pointers. But
then the pointers could be to other mallocated stuff, so your proposed
primitive makes sense.
Andrei
More information about the Digitalmars-d
mailing list