Stack allocation limit for programs on a Linux 32 bit machine

后端 未结 3 1525
礼貌的吻别
礼貌的吻别 2021-01-16 11:45

In C++ how much can the stack segment grow before the compiler gives up and says that it cannot allocate more memory for stack.

Using gcc on a linux (fedora) 32 bit

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-16 12:08

    Under UNIX, if you are running bash run

    $ ulimit -a
    

    it will list various limits including stack size. Mine is 8192kb. You can use ulimit to change the limits.

    Also, you can use ulimit() function to set various limits from within your program.

    $ man 3 ulimit
    

    Under Windows see StackReserveSize and StackCommitSize

    In practice stack addresses begin at high addresses (on a 32-bit platform, close to the 3GB limit) and decrease while memory allocation begins at low addresses. This allows the stack and memory to grow until whole memory is exhausted.

提交回复
热议问题