Created
July 21, 2013 21:47
-
-
Save sonney2k/6050121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <iostream> | |
#include <vector> | |
int main() { | |
int *c = (int*)malloc(sizeof(*c)); | |
int *old_c = c; | |
size_t cnt_c = 0; | |
std::vector<int> v(1); | |
//v.reserve(100000000); | |
int *old_v = &v[0]; | |
size_t cnt_v = 0; | |
for (size_t i=0 ; i<1000000 ; ++i) { | |
v[i] = i; | |
v.resize(100*i+2); | |
if (old_v != &v[0]) { | |
++cnt_v; | |
} | |
old_v = &v[0]; | |
} | |
std::cout << "realloc() reallocations: " << cnt_c << std::endl; | |
std::cout << "std::vector reallocations: " << cnt_v << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment