Using emplace leading to memory corruption

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Sep 29 05:59:57 PDT 2013


On 9/29/13 5:29 AM, lomereiter wrote:
> You didn't tell GC that the allocated memory contains pointers to GC'd
> data.
> Therefore, it thinks that the class members can be freed, which is not
> the case.
>
> Adding lines
>> import core.memory; GC.addRange(tmp, size);
> resolves the problem. You must also call GC.removeRange(tmp) when you
> will free the allocated memory.
>
>>       void[] mem = tmp[0..size];                           // 39
>>       _foo = emplace!(Foo)(mem);                           // 40
>

I tried that and it still crashes. I don't think that's the problem. 
Puneet, the code looks legit, please file a bug report.

Andrei



More information about the Digitalmars-d mailing list