4 ms·
So I suppose there are two false modes of thought: Manual memory management is intrinsically faster, and we really need this performance (sans profiling of cou
by Verdex 12y ago
So I suppose there are two false modes of thought: Manual memory management is intrinsically faster, and we really need this performance (sans profiling of course). On the manual memory management side the interesting thing to investigate is everything that malloc and free actually do. It was quite the eye opener when I saw an allocator implementation for the first time. I guess that's one of the reasons super critical real time applications don't allow heap allocations (ex. check out rule 5 of the JPL coding standard [1]). On the performance side the standard plea continues to be invaluable, please profile before optimizing.
On the other hand, data locality and prefetching is like getting the invincibility star in mario (which you touched on with your std::vector caveat, also checkout about 24 minutes into [2] for some pretty graphs and an explanation). And sometimes you really do need the ability to get all of the performance your machine can give you.
The above dichotomy is very frustrating to me because regardless of which side you fall on there are embarrassing failures. Obviously, if you don't need the performance it's not good that a bunch of needless energy is spent on "performance improvements". But if you do really need the performance, then you get to deal with the "we're doing it in c/c++ therefore it's fast" discourse. And finally assuming that your group really does appreciate c/c++ and understands how to achieve high performance, then you still have to deal with c/c++ in the non-performance related aspects of your product.
For this reason, I've been glancing hopefully in Rust's direction. Maybe it (or some other future language like it) can help alleviate the pressures between GC and manual memory management. A system where both are possible and neither are required sounds ideal. And if we are very lucky maybe it will spark additional dialogue in our industry concerning when we need manual memory management and when we need GC.
[1] - http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf
[2] - http://channel9.msdn.com/Events/Build/2014/2-661 http://channel9.msdn.com/Events/Build/2014/2-661