max array size?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nokci
    New Member
    • Apr 2010
    • 3

    max array size?

    i am writing a code to create a 2600 * 1000 array after reading a .txt document that is filled with random letters (2.4 mb of random letters). When i try to run the program it just halts and none of my check points show up (cout << "a";). here is my code:

    Code:
             string key="C:\\key.txt";
             ifstream inFile;
             int i=0;
             int j=0;
             const int ROW = 2600;
             const int COL = 1000;
             char keyarray[ROW][COL];
             char ch;         
             
             cout << "ab";
             inFile.open(key.c_str());
             
             if (inFile.fail())
             {
                               cout << "not properly opened";
                               exit(1);
             }
             
             
             cout << "bc";
             
             for (j=0; j<=ROW; j++)
             {
                 cout << "a";
                 for (i=0; i <= COL; i++)
                 {
                     cout << "c";
                     inFile.get(ch);
                     keyarray[j][i]=ch;
                     cout << keyarray[j][i];
                     cout << "d";
                 }
             }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Are you sure? Did you check the hard disk light? Did you check the Task Manager? May be it just paused to allocate that array of yours keyarray which is rather large.

    Comment

    • Dheeraj Joshi
      Recognized Expert Top Contributor
      • Jul 2009
      • 1129

      #3
      Does your code has a main function and include statements? or you ignored them while posting assuming we will consider it while reading?

      Regards
      Dheeraj Joshi

      Comment

      • nokci
        New Member
        • Apr 2010
        • 3

        #4
        Originally posted by dheerajjoshim
        Does your code has a main function and include statements? or you ignored them while posting assuming we will consider it while reading?

        Regards
        Dheeraj Joshi
        i just ignored them to save space

        Comment

        • nokci
          New Member
          • Apr 2010
          • 3

          #5
          Originally posted by Banfa
          Are you sure? Did you check the hard disk light? Did you check the Task Manager? May be it just paused to allocate that array of yours keyarray which is rather large.
          it crashes when i run it and if i try to debug its says : "An access violation (segmentation fault) raised in your program"

          Comment

          • jkmyoung
            Recognized Expert Top Contributor
            • Mar 2006
            • 2057

            #6
            ?Guessing it's a memory problem? Perhaps the program continually asks for more memory and waits until it gets it, (which it won't.) There could be a delay opening the file you're asking for.

            Have you tried and run with a smaller array? eg 260 X 1000 or even 260 X 200?

            Also, do you really need to store all the data to process it, or can you use some sort of stream instead?

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              The error may well be on lines 22 and 25. The loop conditions are causing you to access data outside the boundaries of the array.

              If you declare an array with dimension N int array[N]; for example then the valid array indexes are in the range 0 to N - 1 that is in the declaration you request the actual number of entries in the array and those entries are numbered from 0.

              Your loop conditions cause j to have values in the range 0 to ROW and j to have values in the range 0 to COL.

              When either j == ROW or i == COL you therefore are accessing data outside the object keyarray.

              That could easily cause a segmentation fault and is certainly undefined behaviour.

              Comment

              Working...