0

I am writing some code that requires me to use a 2D integer array that is size 50000x50000. Unfortunately, every single time I try to do this, I end up getting a segmentation error. I am currently using the repl.it IDE. Do you know any way in which I can increase the maximum size of a 2D array in repl.it? If this is not possible, could you give me some data structures that can be used as substitutes for a large 2D array?

I have checked all other parts of the code I am writing and can confirm that the segmentation error is not caused by anything other than the 2D array.

I have also seen some solutions that involved configuring the Replit but was unsure of how to implement them.

Full error message -> "signal: segmentation fault (core dumped)"

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Username1
  • 11
  • 1
  • 3
    The array is too big be allocated on your stack. Use std::vector> or manage your memory allocation with std::make_unique so it will be allocated on the heap. – Pepijn Kramer Jan 07 '22 at 09:32
  • 4
    The solution is not to use repl.it, it’s not made for this. Also, a 5000x5000 integer array uses 10 GiB of memory. That’s quite a lot. You probably want to think of a smarter solution that requires less memory. And, yes, obviously you can’t allocate such data on the stack, you need to heap-allocate it. – Konrad Rudolph Jan 07 '22 at 09:32
  • 2
    You might want to do some research about *sparse* matrices? Or use other data-structures depending on your use-case (which we know nothing about). – Some programmer dude Jan 07 '22 at 09:36
  • In particular, virtual servers with that much memory, running for enough time to use all of it, start to cost significant money. You shouldn't really expect free services to provide so much resources. Someone has to pay, and at some point, that someone is you. – Nate Eldredge Jan 08 '22 at 17:20

0 Answers0