scope class members -> in-situ

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Oct 2 08:33:15 PDT 2009


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



More information about the Digitalmars-d mailing list