News for hackers. Stuff that matters.
Re:Drop millions of allocations by using a linked list (2015) by captain_price7 on Friday March 12, 2021 @06:13AM (#26434494)
I think for C++ vector, when current underlying array gets filled, the common strategy is allocate a new array double the size of the current one, and copy contents over to that.
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.
Re:Drop millions of allocations by using a linked list (2015) by tester34 on Friday March 12, 2021 @06:40AM (#26434687)
same in C# for list