Memory Corruption Issue??

Daniel Kozak via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 20 03:52:27 PST 2016


On Wednesday, 20 January 2016 at 11:49:29 UTC, Daniel Kozak wrote:
> On Wednesday, 20 January 2016 at 09:12:57 UTC, Bottled Gin 
> wrote:
>> Greetings
>>
>> I am struggling with strange memory corruption issues with 
>> dmd-2.069.2 release.
>>
>> ...
>> ./main
>> Start frop from C
>> 0 -> @�+----------------
>>
>> The last line is the content of an array which is actually 
>> filled with only dashes in the code.
>>
>> Kindly help. I want to make sure that I am not making a 
>> mistake before I file a bug on dlang bugzilla.
>>
>> Regards
>> - Puneet
>
> Another workaround is to use GC.addRoot for dynamic allocated 
> data in Dynamic.proc
>
> void proc () {
>     import core.memory: GC;
>     dash.length = 32;
>     GC.addRoot(cast(void*)dash.ptr);
>     dash[] = '-';
> }

And another one is hold pointer to data:

class Dynamic {
   static char[] space;
   static char[] dash;
   char* dash_ptr;
   void rehash () {
     static Hash hash ;
     hash = new Hash;
     hash.clear();
   }
   void proc () {
     import core.memory: GC;
     dash.length = 32;
     dash_ptr = dash.ptr;
     dash[] = '-';
   }
}


More information about the Digitalmars-d mailing list