Skip to content

Instantly share code, notes, and snippets.

@gcjyzdd
Created December 30, 2019 16:26
Show Gist options
  • Select an option

  • Save gcjyzdd/d7d6e374468ebadcac9efc86a26bd277 to your computer and use it in GitHub Desktop.

Select an option

Save gcjyzdd/d7d6e374468ebadcac9efc86a26bd277 to your computer and use it in GitHub Desktop.
Test if vector elements's address change
// Example program
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<int> a;
a.push_back(1);
cout<<&a[0]<<"\n";
int N=1e6;
for(int i=0;i<N;++i){
a.push_back(i+1);
if(i%10000 == 0) cout << &a[0] << "\n";
}
return 0;
}
@gcjyzdd
Copy link
Author

gcjyzdd commented Dec 30, 2019

The already pushed elements' address indeed changed when new elements were pushed from the following results:

0x2fdfe90
0x2fdfeb0
0x2feff60
0x65ee6bfca010
0x65ee6bfca010
0x65ee6bf89010
0x65ee6bf89010
0x65ee6bf89010
0x65ee6bf08010
0x65ee6bf08010
0x65ee6bf08010
0x65ee6bf08010
0x65ee6bf08010
0x65ee6bf08010
0x65ee6bf08010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6be07010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a9eb010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010
0x65ee6a5ea010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment