I could use std.c.stdlib.realloc (and I am using, since the GC one throws). I was using the GC version, because GC allows to extend without moving, which can be used in optimized memory buffer structures, that I'm trying to implement. Before trying the GC version, I tried to look for C solutions and all I found was the MSVC's _extend function, which I can't even link in because of COFF vs OMF war.
On Wed, May 9, 2012 at 9:04 PM, Sean Kelly <[email protected]> wrote: > On May 9, 2012, at 8:28 AM, Gor Gyolchanyan wrote: > >> I have a structure: >> >> private struct Block >> { >> this(size_t n) { /* allocate n bytes with GC.malloc */ } >> this(this) { /* deep-copy the bytes */ } >> ~this() { /* deallocate them with GC.free */ } >> } >> >> And a class: >> >> final class Region >> { >> private Block _block; >> alias _block this; >> } >> >> >> This setup allows me to have memory regions, reallocation of which >> will never invalidate pointers, because thanks to Region class no-one >> holds a direct pointer to the memory. >> The problem is, that I get a >> core.exception.InvalidMemoryOperationError when my program ends. > > When your program ends, the class instance is collected by the GC, so you're > effectively calling GC.free within a class finalizer. The GC currently > doesn't support this. Does this memory have to be scannable by the GC or > could you use C malloc instead? -- Bye, Gor Gyolchanyan.
