multidimensional array in a struct leading to core dumps

1
2
3
4
5
6
7
8
9
10
11
12
struct s
{
   string s1;
   string s2;
   vector<float> v1;
   vector<float> v2;
   vector<float> v3;
   float arr1[100][100][100];
   float arr2[100][100][100][100]; // PROBLEM
}

vector<s> container;


For simplicity, lets just look at the primary struc that is causing the core dump. The code compiles and runs with no errors iff "arr2" is commented out.

What is the proper way to initialize "container"?
1. You do realize that arr2 requires at least 381 MiB of contiguous memory, right?
2. Creating an s like this:
 
s obj;
will never work because the stack is somply not large enough to hold something so big.
 
s *obj=new s;
may work if you have enough memory.
1. you are right
2. i have tried that too. no luck.

I am thinking about decreasing the size of array.

Lets just assume for now that it is required to allocate a data structure of that size...
any other suggestions?

Try breaking up the array. Instead of allocating a huge 4-dimensional array, allocate 100 3-dimensional arrays, for example. If the problem is that there's not enough contiguous memory, that should work.
Topic archived. No new replies allowed.