general questions on reference types versus value types...

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 1 01:43:03 PST 2014


H. S. Teoh:

> you *can* allocate by-value
> types on the heap, e.g., `MyStruct* ptr = new MyStruct(...)`. 
> But it's rare to want to do that; usually if you need to do
> that, you should just use a class instead.

If I create data structures that contain many pointers, like some 
kinds of trees, I usually use heap-allocated structs, to reduce 
memory overhead and simplify the whole structure.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list