On 10/14/16 6:18 AM, Nordlöw wrote:
The following code


import std.algorithm.iteration : filter;
import std.algorithm.mutation : move;
import std.range : iota;

static private struct S
{
    import core.memory : GC;
    @disable this(this);

    this(int x)
    {
        _ptr = cast(typeof(_ptr))GC.malloc((*_ptr).sizeof);
        *_ptr = x;
    }

    ~this() { GC.free(_ptr); }  // scoped destruction

Note: no matter what solution you can come up with, having the GC destroy this struct, and the destructor attempting to free the pointer, is going to result in errors.

Instead, you should use C malloc/free here.

This is what RefCounted does.

-Steve

Reply via email to