C++ and D @ stackoverflow

Brad Roberts braddr at puremagic.com
Sat Jun 12 13:03:37 PDT 2010


On 6/12/2010 8:57 AM, Walter Bright wrote:
> Andrei Alexandrescu wrote:
>> Leandro Lucarella wrote:
>>> Andrei Alexandrescu, el 12 de junio a las 00:32 me escribiste:
>>>> BCS wrote:
>>>>> http://stackoverflow.com/questions/3024136/link-compatibility-between-c-and-d
>>>>>
>>>> I just posted an answer that contains a couple of news.
>>>
>>> As I said with your new RefCounted implementation, unless I'm missing
>>> something, there will be problems if you store pointers (or objects that
>>> have pointers) to the GC heap, as you never communicate with the GC.
>>
>> Could you please give an example? Thanks!
> 
> All you have to do is for your malloc'd data, tell the gc about it so it
> can search the malloc'd data for pointers.
> 
> Add the data with:
> 
>     import core.memory;
> 
>     addRange(p, size);
> 
> and remove it when calling free() with:
> 
>     removeRange(p);
> 
> You don't need to do this if the array elements do not contain any
> pointers or references, for example, if they are an array of ints.

Or, even better:

import core.memory;

void* m = GC.malloc(size);


More information about the Digitalmars-d mailing list