3 ms·
I've seen variations on this trick multiple times. Using threads, using a message sent to self, using a list and a timer to do the work "later", using a list an
by pierrebai 6y ago
I've seen variations on this trick multiple times. Using threads, using a message sent to self, using a list and a timer to do the work "later", using a list and waiting for idle time...
They all have one thing in common: pampering over a bad design.
In the particular example given, the sub-vector probably come from a common source. One could keep a big buffer (a single allocation) and an array of internal pointers. For example of such a design to hold a large array of text strings, see for example this blog entry and its associated github repo:
https://www.spiria.com/en/blog/desktop-software/optimizing-shared-data/
https://github.com/pierrebai/FastTextContainer
Roughly it is this:
struct TextHolder
{
const char* common_buffer;
std::vector<const char*> internal_pointers;
};
This is of course addressing the example, but the underlying message is generally applicable: change your flawed design, don't hide your flaws.
- viraptor 6y agoYes. There's also a number of pool/arena allocators in rust which could be used here instead to drop All entries at once.