Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Large Size Array 1

Status
Not open for further replies.

mirok

Electrical
Jun 27, 2001
36
Hi,

I got a problem in VC++. I am trying to run the following program with VC++ but it terminates. The problem is with the size of array. If I change the arraydimension to 50 everything works prefectry but I need to work with large array size. If you have any information regarding this case please let me know.

Thanks

#include <iostream>
using namespace std;
int main()
{

int n=0;
int p=0;
int k=0;
int l=0;
const dimensionarray=60;
int count[dimensionarray][dimensionarray][dimensionarray][2];
for (n=1; n<dimensionarray; n++)
{
for (p=1; p<dimensionarray; p++)
{
for (k=1; k<dimensionarray; k++)
{
for (l=1; l<2; l++)
{
count[n][p][k][l]=n+p+k+l;
printf("%d",count[n][p][k][l]);
}
}
}
}
cout << "Thanks for Helping me";
return 0;
}
 
Replies continue below

Recommended for you

That's a mighty big array. I don't know what, if any, limits VC++ sets on build-time arrays, but you may want to try making it a run-time array (i.e., allocate/deallocate memory using new()/delete() ).
 
I think you're dealing with memory issues. A 60 x 60 x 60 x 2 dimension array (assuming 4 byte integers) is over 1.7 Mb and finding that much heap space could prove problematic, especially if the array implementation requires contiguous memory. You might want to consider using a temporary table in a DB for your storage.
 
Hi MacGyverS2000,

Thanks for your helpful hint. I was successful in allocating a one dimensional array with a very large size. The only problem I have now is to be able to allocate a
4 dimesional array. Would you please help me agian if you have any idea regarding this case.

Thanks again.
 
If the array truly needs to be 4D, you may want to consider making a 4D array of pointers to make access easier. This is a 1D array of pointers. Each of those array elements points to the start of another set of arrays, also pointers. Do this a few times and you have a nice 4D array, that can be accessed quite easily.

Since the computer is going to view all of this as pointer arithmetic anyway, you're going to see a nice speed increase compared to what you're currently running.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor