0

Is there any compiler option or a method to tell gnu gcc not to use heap?
Like for example in armcc : IMPORT __use_no_heap OR #pragma import(__use_no_heap) can be used in the file to tell the armcc not to use heap. I am looking for something similar in gnu gcc.

Thanks!

aditya3524
  • 175
  • 2
  • 4
  • 12
  • 1
    If you don't use functions that allocate memory from the heap, the heap won't be used. If you use functions that allocate memory from the heap, the heap will be used. It's entirely under your control (subject to you knowing which functions in the libraries you use make allocations from the heap). I'm not aware of a pragma or equivalent, but I've not looked hard and don't plan to. When do you think GCC uses the heap behind your back? (C++ would give one set of answers, but the implication is that you're thinking of C.) – Jonathan Leffler Mar 19 '13 at 01:11
  • During malloc and free. Actually I am trying to link the gnu gcc compiled code with armcc. I don't want to use any heap.If I try to compile the entire thing using armcc, it succeeds but it is failing for gnu gcc.. – aditya3524 Mar 19 '13 at 01:15
  • What do you want it to use for malloc and free instead of heap? If it is your source you could look into alloca, but the code would need to be modified. – dbrank0 Mar 19 '13 at 08:34

1 Answers1

1

You can set heap size in GCC like this:

gcc -Wl,--heap=<size in bytes>

You can set it to zero if you want.

Saswat Padhi
  • 6,044
  • 4
  • 20
  • 25