struct or class
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 24 05:06:05 PDT 2014
On 24/08/2014 11:56 p.m., nikki wrote:
> I come from languages that don't offer structs, I have this json load
> function that has to keep some data and intuitively I've written a
> struct, I've read about the differences, heap vs stack, value vs
> reference, but know I think i am overthinking it.
Here's a simple way of working it out.
If you're using arrays of a type, use classes.
If you're storing lots of data inside it, classes.
If you need inheritance, classes.
If you have simple data for returning/argument passing then struct.
Basically, small, short lived allocations stack. Long lived, large
allocations, classes.
At least that's my opinion.
More information about the Digitalmars-d-learn
mailing list