5 ms·
That's actually not true for .net. The tiny local variables can be structs rather than objects. For example if structs could be used for coordinates in this cha
by viraptor 12y ago
That's actually not true for .net. The tiny local variables can be structs rather than objects. For example if structs could be used for coordinates in this change instead of full objects, they would likely never touch the heap.
- MichaelGG 12y agoExcept it is true because structs are often frowned on, and plenty of things end up as reference types. And arrays are reference types too, so things like string.split have no workaround. Also note that until v4 or so, the CLR had limitations optimizing methods using structs. But yes, the CLR has a far superior design and can avoid some of Java's pitfalls.
- eropple 12y agoStructs are frowned upon? Since when?
- pmcg 12y agoAnyone writing Minecraft in C# would use a struct for the position vector. There's no good reason to frown upon it in this case.
- bovermyer 12y agoIt's not C#, but here's Minecraft in C++ and Lua: https://github.com/minetest/minetest https://github.com/minetest/minetest
- Arnavion 12y ago>structs are often frowned on Only in the premature optimization sense, and "familiarity with new programmers" sense. There's nothing wrong with using structs. In fact, XNA and many other game programming libraries do use structs to represent position vectors, which is the context of this article. >And arrays are reference types too, so things like string.split have no workaround. If you're okay with going unsafe, arrays can be stackalloc'd.
- Locke1689 12y agoThis is a cultural problem. We use structs all over the place in Roslyn. You need to train your developers on how to appropriately use the features available to them on the platform.
- richdougherty 12y agoHopefully Java will eventually get "value types" too: http://cr.openjdk.java.net/~jrose/values/values-0.html http://cr.openjdk.java.net/~jrose/values/values-0.html