You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From Laurent,
I can see that at a lot of different places in the code (and I have probably done it myself as well), we simply initialize a vector (with zero size) and then call push_back a number of times on it.
Well, since our loops are pretty long usually, we are actually reallocating a quite substantial number of times.
It would be very sound in my opinion to put a reserve(N) command before entering the loop because most of the time we can guess the max size (say nHistograms).
Below is a test of MedianDetectorTest running on WISH.
The vector nums get reallocated about 20 times (with memory swap every time) and its size is doubled every time.
It might be different under windows...
Number of reallocation in MedianDetectorTests for WISH This is the implication of not using reserve after creating a vector 0
From Laurent,
I can see that at a lot of different places in the code (and I have probably done it myself as well), we simply initialize a vector (with zero size) and then call push_back a number of times on it.
Well, since our loops are pretty long usually, we are actually reallocating a quite substantial number of times.
It would be very sound in my opinion to put a reserve(N) command before entering the loop because most of the time we can guess the max size (say nHistograms).
Below is a test of MedianDetectorTest running on WISH.
The vector nums get reallocated about 20 times (with memory swap every time) and its size is doubled every time.
It might be different under windows...
Number of reallocation in MedianDetectorTests for WISH This is the implication of not using reserve after creating a vector 0
The text was updated successfully, but these errors were encountered: