How do I reduce the heap size of a program to see how it behaves when it runs out of memory?
c, malloc
Solution
You can specify stack and heap sizes like this:
gcc -Wl,--stack=xxxxx -Wl,--heap=yyyyy ...
Problem
I am currently writing a program that allocates memory in various places. I am interested in seeing how my program behaves when the heap runs out of memory, namely when when malloc() returns NULL. Is there a compiler option that can let me set the heap size to something very small so I can see what happens immediately? I am using the gcc compiler.