3 ms·
> C++ is what you get when, at every turn in the language design road, you choose to take the path that leads to higher performance. You have plenty of perform
by ndh2 10y ago
> C++ is what you get when, at every turn in the language design road, you choose to take the path that leads to higher performance.
You have plenty of performance with C, and C++ is what you get when you enforce C compatibility at all costs, then tack on other stuff. The memory layout that classes and class hierarchies force upon you lead to sub-optimal caching behavior. Virtual functions don't have optimal performance, but they still made the cut. Pointer aliasing actually hurts performance as it prevents the compiler from doing optimizations.
I do agree with everything that was said in "The Joy Of C++", bonus points for acknowledging the Stockholm syndrome. However, pretty much all of it could be said about C.
- lossolo 10y ago> The memory layout that classes ... force upon you lead to sub-optimal caching behavior. Simple classes have the same memory layout as C structs, contiguous chunk of memory which means they are cache friendly.
- ndh2 10y agoNo, they're not cache friendly. The problem is row-based vs column-based. Array of structs vs Structure of arrays. With arrays of structs/objects you get row-based access patterns. Especially for cases where you only want to access one or two columns, you always pull in everything else. https://www.youtube.com/watch?v=rX0ItVEVjHc https://www.youtube.com/watch?v=rX0ItVEVjHc
- lossolo 10y agoSoA layout is of advantage when the components that you split into separate arrays are usually accessed separately which in most cases is not true. For most cases it is cache friendly (unless you use niche DoD).
- corysama 10y agoAre there any popular languages that support SOA 1st-class? C++ is largely competing with GC languages where it is difficult to avoid separated heap allocations for every tiny bit of data.
- nicwilson 10y agoWhile not 1st class, in D you can do a completely transparent library solution, because you can introspect the fields of the struct you want to be SoA and insert arrays of those fields in to the SoA'd type. Á la https://github.com/economicmodeling/soa https://github.com/economicmodeling/soa
- netheril96 10y agoAnd in what languages are structure of arrays common?
- smitherfield 10y agoIt's common to structure data as arrays in Fortran and other scientific computing. No reason you couldn't in C or C++.