vector of vectors memory release
vector of vectors memory release
- Subject: vector of vectors memory release
- From: "julian mann" <email@hidden>
- Date: Tue, 3 Oct 2006 18:12:14 +0100
Hi there
I've been trying to track down a memory problem concerning stl vectors and can't figure out where I'm going wrong. I can't believe there is a bug with std::vector on mac, but having said that, there is no leak with this code on Win or Linux.
So - check out the code below -
If I enter 100,000 for x and 10 for y I get 1,000,000 matrices in a 2d array - that is - a vector of 100,000 vectors, each containing 10 matrices.
This takes up about 200 Mb (which seems a lot - but that's not the point)
The thing is, once control returns from makeData(), all that memory should be freed. I'm not using any pointers or doing anything fancy. Looking at the activity monitor, memory drops a tiny bit on leaving makeData().
I compiled this with GCC 4 - but the same problem exists in a Maya plugin I'm writing which uses GCC 3.3
Ideas anyone?
Am I missing something?
Thanks
#include <iostream>
#include <vector>
#include <string>
struct matrix {
double m[4][4];
};
typedef std::vector<matrix> vm;
typedef std::vector<vm> vvm;
int makeData(int x, int y){
vvm myData;
for (unsigned i = 0;i<x;i++)
myData.push_back( vm(y) );
int c;
std::cout << "examine memory now - enter any number to leave this function so the vectors go out of scope ..";
std::cin >> c ;
return x*y;
}
int main (int argc, char * const argv[]) {
int x, y;
std::cout << "enter number of vectors in the big vector ...";std::cin >> x;
std::cout << "enter number of matrices per vector ...";std::cin >> y;
std::cout << "num matrices " << makeData(x,y) << std::endl;
int c;
std::cout << "examine memory now -- enter any number to exit.."; std::cin >> c;
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden