Static allocation of huge amounts of memory inside the main function

后端 未结 2 668
半阙折子戏
半阙折子戏 2021-01-21 07:03

I have a program that has to declare a huge integer array of the size 1000000 in C (using GNU GCC compiler). I tried to declare the array in two different ways.

The tw

2条回答
  •  一整个雨季
    2021-01-21 07:40

    The second version allocates on the stack, the size of which may be limited on your system for any given process. The first one allocates in the data segment of the process, the size of which isn't limited (at least for these orders of magnitude of allocation size)

    From this SO answer you can learn how to check for the stack allocation limit for various platforms like Linux and Windows. If you're on Linux it's as simple as:

    ulimit -a
    

提交回复
热议问题