473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

max array size?

3
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:

Expand|Select|Wrap|Line Numbers
  1.          string key="C:\\key.txt";
  2.          ifstream inFile;
  3.          int i=0;
  4.          int j=0;
  5.          const int ROW = 2600;
  6.          const int COL = 1000;
  7.          char keyarray[ROW][COL];
  8.          char ch;         
  9.  
  10.          cout << "ab";
  11.          inFile.open(key.c_str());
  12.  
  13.          if (inFile.fail())
  14.          {
  15.                            cout << "not properly opened";
  16.                            exit(1);
  17.          }
  18.  
  19.  
  20.          cout << "bc";
  21.  
  22.          for (j=0; j<=ROW; j++)
  23.          {
  24.              cout << "a";
  25.              for (i=0; i <= COL; i++)
  26.              {
  27.                  cout << "c";
  28.                  inFile.get(ch);
  29.                  keyarray[j][i]=ch;
  30.                  cout << keyarray[j][i];
  31.                  cout << "d";
  32.              }
  33.          }
Apr 15 '10 #1
6 2960
Banfa
9,065 Expert Mod 8TB
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.
Apr 15 '10 #2
Dheeraj Joshi
1,123 Expert 1GB
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
Apr 15 '10 #3
nokci
3
@dheerajjoshim
i just ignored them to save space
Apr 15 '10 #4
nokci
3
@Banfa
it crashes when i run it and if i try to debug its says : "An access violation (segmentation fault) raised in your program"
Apr 15 '10 #5
jkmyoung
2,057 Expert 2GB
?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?
Apr 15 '10 #6
Banfa
9,065 Expert Mod 8TB
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.
Apr 15 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Noah Spitzer-Williams | last post by:
Hello guys, I would like to do something seemingly simple: find out if an element in an array that is passed to my function exists. I used to think I could just do: if (arr) ... However, if...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
3
by: ritchie | last post by:
Hi all! Still working on this program! Just to recap, I am writing a program to sort an array with four different sort algorythms. I am having a little trouble at the moment though! Now, I...
8
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line...
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
22
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a...
7
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For...
12
by: manochavishal | last post by:
Hi, I have a question. How can i know the size of array when it is passed to a function. For Example i have this code: #include <stdio.h> #include <stdlib.h>
20
by: Cyn | last post by:
Hi, I want to create a general array structure which can hold all types. Something like this: struct ARRAY { void **array; size_t size; };
28
Nepomuk
by: Nepomuk | last post by:
Hi! I've read, that in C++ there's no predefined method, to calculate the size of an array. However, it's supposed to work withsizeof(array)/sizeof(array)Now, this does work in some situations, but...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.