Please help with GC exception!
Sean Kelly
sean at invisibleduck.org
Wed May 9 10:04:09 PDT 2012
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?
More information about the Digitalmars-d
mailing list