Segmentation Fault While Creating Large Arrays in C

前端 未结 2 1520
生来不讨喜
生来不讨喜 2020-11-28 17:02

you guys have helped me so much with this code. Let me preface by saying I do not know C very well and am trying really hard to do this.

This is what the program sho

相关标签:
2条回答
  • 2020-11-28 17:10

    You probably don't have 10 megabytes of stack space. Make that array global, declare it with static, or allocate it dynamically using malloc(). If you choose the latter, don't forget to free() it.

    Later, when you need to use the 100,000,000 element array, make sure to use a new allocation for it!

    0 讨论(0)
  • 2020-11-28 17:23

    Well there is no way you are going to have that amount of space available on the stack. Allocate it off the heap using malloc(). Remember to free() it afterwards.

    0 讨论(0)
提交回复
热议问题