Last update December 5, 2011

Coming From /
CPlus Plus



Porting is covered in PortingFromCxx

Memory

Allocation for Objects

D creates objects on the heap by default, using "new".

So these definitions:

// class A { ... };

A a;
A atab[...];

hold object references (initialized to NULL). The object data itself will be allocated on the heap when you create the objects (using "new").

To allocate on the stack (IIRC this is supported only in function scope):

class C { ... }

void raii_demo()
{
	scope c = new C();	// c is allocated on the stack
	// use c
	// c will now be destroyed, calling destructor first as expected
}

Related


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: December 5, 2011 22:30 (diff))