I know reserve(n) only allocate n space but size is zero.
while resize(n) allocate n space and size is n.
but when I observe the memory change by window task manager in the test , I'm confused by the result.
I have a code already take 100MB, then I test the code below step by step:
vector<Eigen::Vector4f> vec;
vec.resize(5000000); //memory still take 100MB???
vec.push_back(Eigen::Vector4f::Zero()); //memory take 181MB???
I'm curious why resize didn't change the memory until there is a push_back
vector<Eigen::Vector4f> vec;
vec.reserve(5000000); //memory still take 100MB???
for(int i = 0 ; i < 5000000; i++){
vec.push_back(Eigen::Vector4f::Zero()); // memory increase one by one from 100MB to 181MB
}
reserve also didn't allocate memory ? why?