Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.



> 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.


No, 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


SoA 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).


Are 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.


While 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


And in what languages are structure of arrays common?


It's common to structure data as arrays in Fortran and other scientific computing. No reason you couldn't in C or C++.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: