4 ms·
No. Non-reference plain old structs are typically more efficient for most operations, up to a certain size (how large, 16, 32, 64 bytes?). Objects have a certa
by jstimpfle 10y ago
No. Non-reference plain old structs are typically more efficient for most operations, up to a certain size (how large, 16, 32, 64 bytes?).
Objects have a certain overhead, for example each reference uses 8 bytes, and they typically come with a vtable.
Also cache efficiency is very important these days. Sharing is detrimental unless memory consumption is an issue.
And let's not think about GC overhead. A point class holding two integers is a really bad idea when you have millions of points.
Conversely, as objects get larger, it's less likely for two objects to be equal. Interning is just a bad idea for most cases.