Memory Corruption Issue??

Bottled Gin via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 20 05:58:46 PST 2016


>> 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[] = '-';
>   }
> }

Daniel, thanks for confirming the bug and for providing 
workaround. The second workaround (saving the pointer) will not 
work on my real project though. I have multiple threads and the 
TLS variable will have a different pointer on each thread.

Also, can you please tell me how to addRoot an assoc array to GC. 
It seems there is no ptr property available for assoc arrays.

Regards
- Puneet





More information about the Digitalmars-d mailing list