very large objects

Hi,
sorry for being a complete beginner.

I want to create a very large object.
If it were possible for example an array:
float thingy[6000][6000][50];

Since that is too large for an array I created nested vectors of the same dimensions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int K=50, J=6000;

// create a vector of zeros of length K
vector <float> addK; 
for (int i=0;i<K;i++){addK.push_back(0);}

// create a matrix of zeros of dimension JxK
vector < vector <float> > addJK;
for (int i=0;i<J;i++){addJK.push_back(addK);}

// create a matrix of zeros of dimensions JxJxK
vector < vector < vector <float> > > big;
for (int i=0;i<J;i++){
big.push_back(addJK);}


But this is way too slow to work with.
The memory seems to be full half way through

Is there a way to do this efficiently?
Maybe a way to split this big "matrix" up?

Thanks a lot
Since that is too large for an array


Only on the stack. If you use new you can have that (provided you've got 8GB of RAM, that is - 6000*6000*50*4 bytes per float = a bit under 7GB, or a bit under 14GB if you're using 8 byte floats). That said, multi-dimensional arrays are a pig.
Last edited on
What are you trying to do? Why do you need so much RAM?

Possible fixes:
1) Find a way to work with the data one at a time, so you don't need it all in memory at once.
2) Declare it in program memory, instead of on the stack.
3) Use the hard drive, instead of RAM.
etc...
Topic archived. No new replies allowed.