Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General cleanup of std::vector usage #1671

Closed
martyngigg opened this issue Aug 17, 2009 · 1 comment
Closed

General cleanup of std::vector usage #1671

martyngigg opened this issue Aug 17, 2009 · 1 comment
Assignees
Milestone

Comments

@martyngigg
Copy link
Member

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

 1
 Adress0x7f4489a78e70
 2
 Adress0x7f4489a78e50
 4
 Adress0x7f449bb7cfc0
 8
 Adress0x7f4486e7bc80
 16
 Adress0x7f4486e7bcd0
 32
 Adress0x7f4486e7b8a0
 64
 Adress0x7f43d90fd830
 128
 Adress0x7f448e377e70
 256
 Adress0x7f448b677e70
 512
 Adress0x7f448dd77e70
 1024
 Adress0x7f4490d7af40
 2048
 Adress0x7f44a4a789f0
 4096
 Adress0x478d3a0
 8192
 Adress0x47953b0
 16384
 Adress0x7f43a92dc760
 32768
 Adress0x7f43a9100010
 65536
 Adress0x7f43a9140020
 131072
 Adress0x436aee0
@martyngigg
Copy link
Member Author

This issue was originally trac ticket 823

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants