减少内存分配GCC命令 [英] Reducing memory allocation GCC command
问题描述
在调试我的应用程序时,我可以从这个编译器功能中受益匪浅,因为我需要正确处理分配错误,这在我的PC上使用超过16 GB的RAM非常棘手。
有人知道这个选项是什么吗?我希望像 gcc --maxalloc 1024 $ c $这意味着我的程序将能够分配最多1024字节的内存。
我不知道这是一个编译器选项。但是, ulimit
Linux命令可用于限制进程可以使用的内存量。
例如,以下命令将限制从当前shell运行的应用程序的数据段大小:
ulimit -d 1024K
Today, during my computer sciene classes I was told that I can adjust the amount of memory my program can allocate during its compilation (using GCC, Linux). This amount is by default set to optimal mode (which means as much as possible).
I could greatly benefit from this compiler feature during debugging my application since I need to properly deal with allocation errors, which is quite tricky on my PC with over 16 GB of RAM.
Does anyone know what this option is? I expect sth like gcc --maxalloc 1024
which would mean that my program will be able to allocate at most 1024 bytes of memory.
I don't know of a compiler option for this. However, the ulimit
Linux command can be used to limit the amount of memory a process can use.
For example, the following command would limit the data segment size of applications run from the current shell:
ulimit -d 1024K
这篇关于减少内存分配GCC命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!