Maximum size of an array

@princerk i dont think you would be able to increase the stack size of those in codechef… Try some other optimization techniques…

@kcahdog @princerk Can you give example of any such code that clears my above doubt.

@damn_me when u allocate an array of size [10^6][10^6] it will take (10^6)*(10^6) i.e 10^12 which is very much greater then two 1-D arrays of size [10^6] i.e 2 * (10^6) i think it clears ur doubt

1 Like

So as all codechef problems have input data in the order of 10^8, array can’t be used to store input data.So what are the other strategies?I am not able to solve problems bcoz of this and i am stuck from 2 weeks or so.Please help…

I guess declaring it globally would work out!!!

Can you or anyone else please suggest a method to store data greater than 10^6 like in the ranges 10^9 ? Also tell me if can make a bool array of size 10^9 ?

Yes, a bool array of the size 10^9 can be declared

1 Like

how

even i am getting the same error, please if you have found out the solution.

The coderwall explains in Some detail the theory of how best to get the size of an array in C++ Better getting array size in C++ (Example)

Thanks :), I was declaring array of size 10^6 inside main function and I was getting runtime error, declaring the array globally did thejob.

I just checked maximum memory allocation in sublime text 3.

Result -
1. Outside main(), Maximum of 4.9 * 10^8 elements in an integer array are possible.
2. In main(),Maximum of 5.1 * 10^5 elements in an integer array are possible.

Note: My laptop has 8 GB RAM.

In main(), i was not able to allocate the memory more than 2 MB but outside main() 1996 MB can be allocated.

In main(), See code for 1D array:

  int b[519288];
  cout<<sizeof(b)<<endl;  //output - 2077152 (2 MB)

Even Increasing the memory by 1 was not giving me output.


In main() See code for 2D array:

  int b[720][721];
 cout<<sizeof(b)<<endl;  //output - 2076480 (2 MB)

Even Increasing the memory by 1 in any dimension was not giving me output.


Outside main(), See code for 1D array,

int b[499104999];
main()
{
 cout<<sizeof(b);  //Output - 1996419996 (1996 MB)
}

Even Increasing the memory by 1 in any dimension was not giving me output.


Outside main(), See code for 2D array,

int b[22340][22341]; //199999999
int main()
{
	cout<<sizeof(b)<<endl;  //Output - 1996391760 (1996 MB)
}

Even Increasing the memory by 1 in any dimension was not giving me output.

Try using memset (v, true, sizeof (v));

This post was flagged by the community and is temporarily hidden.

My sieve computes primes till a billion and stores the primes in memory, there are 5x10^7 primes under a billion. So max array size in c++ for unsigned int is atleast 5*10^7. For bool array probably you can reach 10^9.

hey how to declare it globally. plz give some examples using it.