In one time-critical part of the program there is a member of the class that looks like that: std::vector m_vLinks; During profiling I noticed that about 99.98% of executions this vector holds only 0 or 1 items. However in very rarely cases it might hold more. This vector is definitely a bottleneck according to profiler, so I'm thinking about following optimization:
Before starting to prototype this thing to see if it helps, I wonder if anyone encountered custom containers with similar functionality in some 3rd-party libraries?
I already thought about boost::array, but don't want size limit that it imposes
LLVM has a class for that called SmallVector.
In a non-time-critical part of your code, perform: m_vLinks.reserve(1);
. That way, in the time-critical part, there will typically be no dynamic allocation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With