Here is what I’m doing.
I have a class which I instance and it has a std::vector.
when I first instance the class this std::vector is empty.
The way I use it is I exponentially add to it and clear. Ex:
Add a number, clear the vector:
Add 2 numbers, clear the vector:
Add 3 numbers, clear the vector,
Add 4 numbers, clear the vector.
……
Is a std::vector the bst way to do what I’m doing?
I tried to do reserve(100,000) in the constructor but this did not help.
Is there maybe a better container for my usage?
Thanks
Your algorithm appears to be quadratic. If you really need 100,000 elements, you’re adding an element 1 + 2 + 3 + … + 100,000 times. That’s about 5,000,000,000 operations. That many operations, no matter how trivial they are, will take a while on a standard pc, regardless of whether you’re using
std::vectoror hand-crafted assembly language.