News for hackers. Stuff that matters.
Re:Records Come to Java by anthonybsd on Thursday January 16, 2020 @07:06PM (#22070489)
Reference; heap;

They are data containers, not control structures.

Re:Records Come to Java by GordonS on Friday January 17, 2020 @04:03PM (#22079296)
Can't you use structs in C# as data containers?
Re:Records Come to Java by anthonybsd on Friday January 17, 2020 @04:33PM (#22079607)
Ughh, you can provided that they are

1) Small 2) Short lived.

Because they live on the stack and follow the rules of value types you really shouldn't be using them for anything major. I.e. you want to model a SQL query result for a table with more than 3 columns? Probably struct is NOT the way to go, use a POCO class.

Re:Records Come to Java by GordonS on Friday January 17, 2020 @04:38PM (#22079667)
C# structs don't always live on the stack (unless you use a ref struct)[0]

[0] https://kalapos.net/Blog/ShowPost/DotNetConceptOfTheWeek16-R...

Re:Records Come to Java by anthonybsd on Friday January 17, 2020 @04:51PM (#22079830)
Well of course. Just like an int doesn't always live on the stuck. I.e. when it's declared as a field for example. If you are piping data from SQL DB into a List<YourStruct> the list is a reference type and will of course be on the heap.

Another issue with struct being big is really when it's being passed around and value copying starts to occur. You want to minimize this if the struct is large. My point being is that if in doubt, you probably don't want to use a struct and hence it's not a general purpose data container.