-3

I am getting "RE (SIGSEGV)" for the following line of code:

int dp[105][100005];

My laptop has 8GB of RAM. Is it not sufficient to store 10^7 integers?

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • The stack size allocated to each process is limited by default, usually to a few megabytes, so 10^7 integers is very likely to overflow it. We have a question somewhere about large local arrays causing stack overflow, but I can't find it right now. The short answer is that you ought to allocate it dynamically instead, which should give you access to all the machine's memory (subject to various limitations). – Nate Eldredge Feb 09 '21 at 22:36
  • In every question, please always include a tag for the programming language you are using. I'm guessing [tag:c] from the syntax, but please update the tags if not. – Nate Eldredge Feb 09 '21 at 22:37

1 Answers1

0

It is if you dynamically allocate, as in:

int* dp = calloc(105 * 100005, sizeof(int));

Where you can use that 1D array in a 2D fashion via offset calculations.

You cannot fit something this big on the stack, it's just too huge. The stack is limited in size.

tadman
  • 208,517
  • 23
  • 234
  • 262