Comment by tetromino_
9 years ago
> If you can't afford to use dynamically allocated memory at all, then there's nothing special about STL, you need to avoid all libraries that call malloc().
I think the idea (as seen in traditional high-performance C++ code) is to be very aware of allocations. Dynamic memory allocation is slow; sometimes, the slowest part of one's code. So it's fine to use a library that calls malloc() behind your back for small, occasional allocations (whether that library is the STL or libc or any of your other dependencies), but not in your inner loops, and not for your multi-GB data structures. Instead, manage your own buffers, size them right from the beginning using application-specific logic, realloc exponentially if you need to (but hopefully you don't need to), and use placement new to construct your objects in your buffer in a way to optimize access locality.
No comments yet
Contribute on Hacker News ↗