本文介绍了如何强制程序出现内存不足?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个C / C ++程序,当内存不足时可能挂起。我们通过同时运行多个副本来发现这一点。我想调试程序,而不会在开发机器上完全破坏性能。有没有办法限制可用的内存,以便在请求500K的内存之后,新的或malloc将返回NULL指针?I have a C/C++ program that might be hanging when it runs out of memory. We discovered this by running many copies at the same time. I want to debug the program without completely destroying performance on the development machine. Is there a way to limit the memory available so that a new or malloc will return a NULL pointer after, say, 500K of memory has been requested?推荐答案尝试在头上转动问题,并询问如何限制操作系统允许您的进程使用的内存量。Try turning the question on its head and asking how to limit the amount of memory an OS will allow your process to use.尝试查看 http://ss64.com/bash/ulimit.html尝试说: ulimit -vTry say: ulimit -v这是另一个有点旧的链接,但是再多一点:$ b​​ $ b http://www.network-theory.co.uk/docs/ gccintro / gccintro_77.htmlHere is another link that's a little old but gives a little more back ground:http://www.network-theory.co.uk/docs/gccintro/gccintro_77.html 这篇关于如何强制程序出现内存不足?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 21:31