The Dark Side of .reserve()
Logan Smith
0:00 / 0:00
The Dark Side of .reserve()
244 581 просмотр · 3 года назад
Logan Smith
50 тыс. подписчиков
244 581 просмотр · 3 года назад
.reserve(...) is a method you might've seen in the API of your favorite dynamic array (or hash table or whatnot), and it's an excellent tool for making simple, impactful performance optimizations while you are building up data structures. But just like all tools, it has sharp edges. In this video we'll dive into where .reserve() can make your performance sing--and where it can be devastating.
Special guest appearances from Unreal Engine, spline points, big-O notation, amortized constant complexity, exponential growth, C++ STL algorithms, good Rust design choices, and me forgetting to use the oldSize variable in the call to .resize() on the next line (but it's okay, I use it later on).
Starring:
std::vector::reserve - https://en.cppreference.com/w/cpp/con...
Vec::reserve_exact - https://doc.rust-lang.org/std/vec/str...
TArray - https://docs.unrealengine.com/5.2/en-...
USplineComponent - https://docs.unrealengine.com/5.2/en-...
FBVector (great docs on selecting a good growth factor) - https://github.com/facebook/folly/blo...
Contributing to Unreal - https://docs.unrealengine.com/5.2/en-...
I use the amazing Manim library for animating these videos, and I edit them with Blender and Audacity.
https://www.manim.community/
https://www.blender.org/
https://www.audacityteam.org/