I think this has been discussed in this group already.

An object storing another object needs two allocations:

class A { ... }
class B {
   A a;
   this() {
      a = new A;
   }
}

auto b = new B; // two allocations

I'm thinking of using "scope" in this situation to imply in-situ storage:

class B {
   scope A a;
   this() {
      a = new A;
   }
}

Now the A member actually lies inside of B - no more indirection. That means the constructor needs special scrutiny, in particular a cannot be null because that wouldn't make much sense.

What do you think?


Andrei

Reply via email to