如何增加 macOS 中的堆栈大小以运行 C/C++程序?
因此,我必须增加堆栈大小才能运行 C/C++ 程序。现在,通过我的在线搜索,我发现了相互矛盾的答案。但一般方法是使用 ulimits 来增加它。 我可以看到我的初始堆栈大小是 8176 KB,现在,我首先尝试将其增加到 18,000 KB,似乎有效。但是,我无法让它超过硬限制,有没有办法在 MacOS 中增加这个硬限制?
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -s
8176
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -s 18000
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -s
18000
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -Hs
65520
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -s 65521
ulimit: value exceeds hard limit
So, I have to increase my Stack Size for running a C/C++ program. Now, from my online search I have found conflicting answers. The general way though is to increase it using ulimits
.
I can see that my initial stack size is 8176 KBs, Now, I first tried to increase it to 18,000 KBs, it seems to have worked. But, I can't get it to exceed the Hard Limit, is there a way to increase this hard limit in MacOS?
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -s
8176
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -s 18000
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -s
18000
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -Hs
65520
vedantamohapatra@Vedantas-MacBook-Air ~ % ulimit -s 65521
ulimit: value exceeds hard limit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在链接程序时将
-stack_size size
传递给链接器来增加 macOS 程序的堆栈大小。ulimit
不会更改程序请求的堆栈大小;它改变了系统将授予的请求。在解决在线评审或竞赛中,增加筹码堆大小通常是一种糟糕或不正确的方法。通常有两种解决方案:寻找另一种需要更少内存的算法或使用动态分配。竞赛问题的设计通常使得简单的方法需要过多的内存,但有些聪明的方法则不需要。
You can increase the stack size of a macOS program by passing
-stack_size size
to the linker when linking the program.ulimit
does not change the stack size that a program requests; it changes what requests the system will grant.Increasing the stack size is generally a bad or incorrect approach in solving online judging or contests. There are two solutions that are usually intended: Find another algorithm that requires less memory or use dynamic allocation. Contest problems are often designed so that naïve approaches require excessive amounts of memory but there are smart approaches that do not.