减少内存分配GCC命令 [英] Reducing memory allocation GCC command

查看:233
本文介绍了减少内存分配GCC命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,在我的计算机sciene课程中,我被告知我可以调整程序在编译过程中可以分配的内存量(使用GCC,Linux)。这个数量默认设置为最佳模式(这意味着尽可能多)。

在调试我的应用程序时,我可以从这个编译器功能中受益匪浅,因为我需要正确处理分配错误,这在我的PC上使用超过16 GB的RAM非常棘手。



有人知道这个选项是什么吗?我希望像 gcc --maxalloc 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆