Hello,

It is my understanding that a class can have a struct as one of its members, and it will be allocated in-line with the rest of the class' members. My question is this; how might I be able to do this with another class? I want to be able to allocate Foo using std.experimental.allocator without having to pass in a reference to the actual allocator. Thanks.

eg:
class SomeClass {}

class Foo {
    this(IAllocator alloc) {
        sc = alloc.make!SomeClass;
        this.alloc = alloc
    }

    ~this() {
        alloc.dispose(sc);
    }

    size_t something;
    SomeClass sc;
    IAllocator alloc
}

auto foo = alloc.make!Foo(alloc);

vs.

struct SomeStruct {}

class Foo {
    this() {
        ss = SomeStruct (...);
    }

    size_t something;
    SomeStruct ss;
}

auto foo = alloc.make!Foo;

Reply via email to