Hi, I'm completely new to C++. My original goal was to build a columnar based database, and C++ seems an appropriate choice of languages.
Having said that, I'm just trying to learn the language. Having just learned arrays, I decided to write a simple array to test performance if the array was composed of ints, long ints, and long long ints (ints and long ints are both 32 bits, while long long ints are 64).
I'm just trying to create an array of 1 million ints / long ints / long long ints, populate each array value with the number 1 thru 1 million, and then create a 2nd loop to sum them all up.
But here's the odd thing - if I create the array with array size of only 100,000, the code blows up (using a 32 bit compiler). When I use a 64 bit compiler, I can get a larger number, but still can't make even 1 million.
Any ideas what could be wrong? (Code below). An array of a million items isn't very big to me - 1 million * 4 bytes is only 4 Mb. I'm on a machine with 64 bit Windows 7 and 16 GB of ram. To create a columnar database (where the fact table will have tens of millions of rows), I'm starting to get nervous....
Thanks!
Scott
Code:#include <iostream> using namespace std; const int arraySize = 600000; int main() { int myArray [arraySize]; long long int sum = 0; cout << "The array is created." << endl; // first loop to populate the array for (int i=0; i < arraySize; i++) { myArray[i] = i; } cout << "The array is populated." << endl; // second loop to compute sum for (int i=0; i < arraySize; i++) { sum += myArray[i]; } cout << "The array sum is computed." << endl; cout << "The sum of 1 thru " << arraySize << " is " << sum << endl; return 0; }