On Sunday, 14 June 2015 at 01:31:25 UTC, Adam D. Ruppe wrote:
On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote:
I have read that in D structs are always allocated on the stack while classes are always allocated on the heap.

That's not true; it is a really common misconception.

Putting a struct on the heap is trivial and built into the language: `S* s = new S();`

Putting a class on the stack is a bit trickier, but the standard library provides a helper to do it: http://dlang.org/phobos/std_typecons.html#scoped follow the examples given there.

True, but wasn't there a conscientious decision to make structs more amenable to value semantics while classes are more conducive to reference semantics.

I guess the question would be why would one want a struct on the heap and a class on the stack? Performance reasons?

Reply via email to