News for hackers. Stuff that matters.
Re:Drop millions of allocations by using a linked list (2015) by rerx on Friday March 12, 2021 @06:48AM (#26434740)
But if you expect an upper bound of the required size of that stay, it may be worthwhile to explicitly set the capacity of the vector to avoid these reallocations.
Re:Drop millions of allocations by using a linked list (2015) by spacechild1 on Friday March 12, 2021 @08:04AM (#26435387)
That's exactly the purpose of std::vector's “reserve“ method, btw.
Re:Drop millions of allocations by using a linked list (2015) by twoodfin on Friday March 12, 2021 @08:24AM (#26435556)
I once worked with a C++ text processing library that saw more than a 50% throughput bump just from reserve()’ing std::string and std::vector space in hot code paths.