Rationale for classes as reference types

bearophile bearophileHUGS at lycos.com
Fri Aug 8 05:21:35 PDT 2008


A Lahav:
> Agree, and more than that - why shouldn't it be the default case?

If your question is "why aren't classes allocated on the stack by default", the answer is simple: heap allocated classes are safer (and more flexible), you can use them around your program, and the GC takes care of them.

The D language is (I hope) designed to be safe by default when possible (and when it doesn't make the programs crawl), and to give you (when possible) a way to do the unsafe thing if you ask for it explicitly (kind of the opposite of C, see the int x = void; too).

For max speed you have to use C/C++/asm/HLA/etc.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list