Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing memory allocation GCC command

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.

like image 536
Robin92 Avatar asked Dec 20 '22 14:12

Robin92


1 Answers

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
like image 105
Greg Hewgill Avatar answered Dec 23 '22 03:12

Greg Hewgill