473,399 Members | 2,478 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,399 software developers and data experts.

Large Array

I have to define an array of 1000x20000 of int in C or C++.
Please help me defining the array of this size.
Jan 31 '07 #1
8 3306
Motoma
3,237 Expert 2GB
I have to define an array of 1000x20000 of int in C or C++.
Please help me defining the array of this size.
Welcome to The Scripts.

Expand|Select|Wrap|Line Numbers
  1. int bigarr[1000][20000];
  2.  
Jan 31 '07 #2
horace1
1,510 Expert 1GB
you will probably have to make it global, e.g.
Expand|Select|Wrap|Line Numbers
  1. int bigarr[1000][20000];
  2. int main(){
  3. ...
  4. }
Jan 31 '07 #3
Welcome to The Scripts.

Expand|Select|Wrap|Line Numbers
  1. int bigarr[1000][20000];
  2.  
Please check whether it is working or not
Jan 31 '07 #4
Welcome to The Scripts.

Expand|Select|Wrap|Line Numbers
  1. int bigarr[1000][20000];
  2.  
Please check once again and confirm back
Jan 31 '07 #5
Ganon11
3,652 Expert 2GB
This code runs perfectly well.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int ROW_SIZE = 1000;
  5. const int COL_SIZE = 20000;
  6. int bigArr[ROW_SIZE][COL_SIZE];
  7.  
  8. int main() {
  9.     int i = 0;
  10.  
  11.     for (int r = 0; r < ROW_SIZE; r++) {
  12.         for (int c = 0; c < COL_SIZE; c++) {
  13.             bigArr[r][c] = i;
  14.             i++;
  15.             if (i % 15000 == 0) i = 0;
  16.         }
  17.     }
  18.  
  19.     cout << "Sample of bigArr..." << endl;
  20.     for (int r = 30; r < 40; r++) {
  21.         for (int c = 40; c < 50; c++) {
  22.             cout << bigArr[r][c] << "  ";
  23.         }
  24.         cout << endl;
  25.     }
  26.  
  27.     system("PAUSE");
  28.     return 0;
  29. }
  30.  
  31. /* Sample Run
  32.  
  33. Sample of bigArr...
  34. 40  41  42  43  44  45  46  47  48  49
  35. 5040  5041  5042  5043  5044  5045  5046  5047  5048  5049
  36. 10040  10041  10042  10043  10044  10045  10046  10047  10048  10049
  37. 40  41  42  43  44  45  46  47  48  49
  38. 5040  5041  5042  5043  5044  5045  5046  5047  5048  5049
  39. 10040  10041  10042  10043  10044  10045  10046  10047  10048  10049
  40. 40  41  42  43  44  45  46  47  48  49
  41. 5040  5041  5042  5043  5044  5045  5046  5047  5048  5049
  42. 10040  10041  10042  10043  10044  10045  10046  10047  10048  10049
  43. 40  41  42  43  44  45  46  47  48  49
  44. Press any key to continue . . .
  45.  
  46. */
Jan 31 '07 #6
This code runs perfectly well.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int ROW_SIZE = 1000;
  5. const int COL_SIZE = 20000;
  6. int bigArr[ROW_SIZE][COL_SIZE];
  7.  
  8. int main() {
  9.     int i = 0;
  10.  
  11.     for (int r = 0; r < ROW_SIZE; r++) {
  12.         for (int c = 0; c < COL_SIZE; c++) {
  13.             bigArr[r][c] = i;
  14.             i++;
  15.             if (i % 15000 == 0) i = 0;
  16.         }
  17.     }
  18.  
  19.     cout << "Sample of bigArr..." << endl;
  20.     for (int r = 30; r < 40; r++) {
  21.         for (int c = 40; c < 50; c++) {
  22.             cout << bigArr[r][c] << "  ";
  23.         }
  24.         cout << endl;
  25.     }
  26.  
  27.     system("PAUSE");
  28.     return 0;
  29. }
  30.  
  31. /* Sample Run
  32.  
  33. Sample of bigArr...
  34. 40  41  42  43  44  45  46  47  48  49
  35. 5040  5041  5042  5043  5044  5045  5046  5047  5048  5049
  36. 10040  10041  10042  10043  10044  10045  10046  10047  10048  10049
  37. 40  41  42  43  44  45  46  47  48  49
  38. 5040  5041  5042  5043  5044  5045  5046  5047  5048  5049
  39. 10040  10041  10042  10043  10044  10045  10046  10047  10048  10049
  40. 40  41  42  43  44  45  46  47  48  49
  41. 5040  5041  5042  5043  5044  5045  5046  5047  5048  5049
  42. 10040  10041  10042  10043  10044  10045  10046  10047  10048  10049
  43. 40  41  42  43  44  45  46  47  48  49
  44. Press any key to continue . . .
  45.  
  46. */


Thank you Very much for the timely help
Jan 31 '07 #7
willakawill
1,646 1GB
I have to define an array of 1000x20000 of int in C or C++.
Please help me defining the array of this size.
Hi. At that size (80mb) I would allocate memory on the heap and I would use a single dimension
Expand|Select|Wrap|Line Numbers
  1. const int COLS = 1000;
  2. const int ROWS = 20000;
  3. int *bigarr = new int[COLS * ROWS];
and the syntax for accessing say bigarr[23][35] is
Expand|Select|Wrap|Line Numbers
  1. myvalue = bigarr[23 + (COLS * 35)];
and in a loop:
Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < COLS; i++)
  2.    for (j = 0; j < ROWS; j++)
  3.       bigarr[i + (COLS * j)] = i + j;
Jan 31 '07 #8
willakawill
1,646 1GB
Forgot to mention that, because we have used the new operator above, we also have to use the delete operator to clean up after us:
Expand|Select|Wrap|Line Numbers
  1. delete [] bigarr;
Jan 31 '07 #9

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

Similar topics

8
by: Pjotr Wedersteers | last post by:
Hello, I tried to create an array with 1000 cells, keys 0 thru 999 using $myarr = array (1000); But this leads to an array of 1 cell with value 1000; Now I have a workable solution for...
2
by: Developwebsites | last post by:
const int MAX=999; class person { protected: char firstname, lastname; int ID; public: person();
2
by: xain | last post by:
HtmlString includes a web page, and soon it is converted to Html file. In the web page, they are images, and some of them are large. They are so large, in fact they are going to destroy my Tables,...
0
by: Marc van Boven | last post by:
I'm stuck with the following problem: My nusoap-client calls a server-function giveCombination(). The function giveCombination should return something like array( => array( 'a_id' => 6,...
5
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied?...
3
by: meltedown | last post by:
Normally, if I use $result=print_r($array,TRUE); print_r prints nothing and $result is equal to the readable array. However, if $array is very large, print_r prints the array and returns...
7
by: ultr | last post by:
I need a large 3D array of structures: struct s { char a; int b; }; s s_array; s_array is declared as global.
6
by: comp.lang.php | last post by:
if (!function_exists('bigfile')) { /** * Works like file() in PHP except that it will work more efficiently with very large files * * @access public * @param mixed $fullFilePath * @return...
10
by: Peter Duniho | last post by:
This is kind of a question about C# and kind of one about the framework. Hopefully, there's an answer in there somewhere. :) I'm curious about the status of 32-bit vs 64-bit in C# and the...
1
by: parvtb | last post by:
I know STL vector works. But in case STL is not available, what can one do to allocate large memory size in c++ through operator "new"? For instance, I am writing a sort algorithm, and here's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.