I have tested on stl vector with code below:
struct structA{
char charArray[256];
}
structA a;
..assign 256 characters to a.charArray
vector<structA> v1;
v1.reserve(1000);
for(int i=0; i<1000; i++){
v1.push_back(a);
}
I realized that for every 16 push_back, there is a spike in the v1.push_back. I suspect that there is a reallocation of memory. I am wondering why is it so since I already use the reserve? I tried to declared the vector using vectorv1(1000), it also gives the same behaviour.
By the way, if I increase the char into 512, it took just 8 push_back, 8 * 512 gives around 4k memory. Would that the issue related to memory paging?
Thanks.
Run this simple test and see if there are any allocations or deallocations you don’t want or don’t expect.