Results 1 to 8 of 8
I need four dimensional array like
double a[256][256][256][256];
but the size is too big to use an array.
If I use only pointer like
double ****a;
to allocate this memory, ...
- 09-29-2007 #1Just Joined!
- Join Date
- Feb 2007
- Posts
- 31
allocation of four dimensional array memory
I need four dimensional array like
double a[256][256][256][256];
but the size is too big to use an array.
If I use only pointer like
double ****a;
to allocate this memory, I have to run 3 loops to allocate memory ..which takes lots of time.
a = (double **** ) malloc (sizeof(double ***)*256);
for(i=0;i<256;i++)
{
a[i] = (double ***) malloc ( sizeof(double **)*256);
for(j=0;j<256;j++)
{
a[i][j] = (double **) malloc ( sizeof(double *)*256);
for(k=0;k<256;k++)
{
a[i][j][k] = (double *) malloc ( sizeof(double )*256);
}
}
}
is there any other work around ....?
I was thinking to use *a[256][256][256]
Can I use this ...and if yes how I can allocate the memory for this...?
- 09-30-2007 #2
If you say something like
then you're asking for 32 gigabytes of main memory. The compiler will choke on this, for very good reasons.Code:double a[256][256][256][256];
Your only hope is to allocate the memory for this in your heap by using malloc(). But even that won't work if you're running 32 bit Linux, because you'd need at least a 36 bit address space for this.
Consider placing this data on disk.
Are you running 64-bit Linux? If so it's theoretically possible to put this data in your heap by using malloc(). If that's the case, let's discuss this further.
Hope this helps.
- 10-02-2007 #3Just Joined!
- Join Date
- Sep 2007
- Posts
- 3
Also, a much better way to allocate this (although, like the previous poster mentioned, this is A LOT of data), would be something like:
double *array = (double*)malloc(256*256*256*256*sizeof(double));
You'll have to manage your own indexing, but it's not too hard
- 10-02-2007 #4
There is no reason to have an array that big.
- 10-02-2007 #5
- 10-02-2007 #6
Well, let me rephrase, unless you have a gigantic amount of static data you need super fast access to, like the kind of stuff you would partition out in an HPC cluster, I see no reason to create an array that big.
- 10-02-2007 #7Code:
Hey, that works for me! ^ | (See? An ASCII smiley, the way God intended!)
- 10-03-2007 #8
Heh, I agree with you wje, use the disk. If the array isn't ever really going to be full maybe a sparse array. A little more detail as to the application and surely some of the crowd here can help.


Reply With Quote
