×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Large Size Array

Large Size Array

Large Size Array

(OP)
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;
}

RE: Large Size Array

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() ).

RE: Large Size Array

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.

RE: Large Size Array

(OP)
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.

RE: Large Size Array

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources