Eigenpoll : D wish list : auto-member objects 

If a class has a lot of members of other classes, when you create an object of that class, first, the memory of this class is allocated, then the constructor is called, where probably the memory of member objects is also allocated. Then the constructors of those member objects are called, which in turn...

All those little memory chunks are a performance bottleneck. It would be nice if you could say that member object memory is to be allocated 'inside of' the memory of the container. In this way, just one allocation would be needed.

The syntax is straightforward:

class Foo
{
int x;
}

class Bar
{
auto Foo foo; // auto-member

this()
{
foo = new Foo; //does not allocate memory
// since foo is an auto-member
...
foo = null; //Error: auto-member can't
//be assigned after initialization
}
~this()
{
//foo.~this() will be called automatically
// at the end of this destructor (RAII)
}
}



Report this item for cleanup