resize multiple dimensional vector array in while loop
ATL / WTL / STL
1
Posts
1
Posters
0
Views
1
Watching
-
Hi ALL, outside a while loop, I declare a 3-D vector array
vector Psodu; Psodu.reserve(10); vector > > structPersonVar(2, vector >(2,Psodu));
in the while loop, i have to change the size of the array in every iteration. First, I use the following code to release the memory
for(int j=0; j < 2; j++) { for(int k =0; k < 2; k++) { vector().swap(structPersonVar[j][k]); } vector >().swap(structPersonVar[j]); } vector > >().swap(structPersonVar);
Then, I resize the arraystructPersonVar.resize(20); for(j=0; j < 12; j++) { structPersonVar\[j\].resize(2); for(int k =0; k < 2; k++) { structPersonVar\[j\]\[k\].reserve(10); } }
I am not very sure whether i am correct by doing in this way,though it works fine with testing program.