This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Circumstances that trigger Heap usage

Hello,

I am developing in NRF51 with gazelle communication. I specify in project setting (in IRAM) to use full RAM of my nRF51, and use MicroLib. My last working application does not use dynamic memory allocation at all, and I verify in produced memory map that arm_startup_nrf51 uses (default size) 2048 stack, no heap at all.

Then, I modify the code, still without dynamic mem allocation, and suddenly I got "no space in execution regions" error, even though the variable and method does not change much. Since it doesn't produce memory map to be checked, I set the IRAM to exceed full RAM of my nRF51 to get successful compilation and memory map.

In the memory map, everything is almost same, except arm_startup_nrf51 uses 4096 now, with heap. I notice this additional usage is heap as it changes the size accordingly every time I change Heap_size in arm_startup_nrf51.s to different size. (for example, I change Heap_size into 1024, now arm_startup_nrf51 use 3072 in memory map).

Is there any circumstance other than dynamic memory allocation that will trigger this heap usage?

*I use default arm compiler of Keil in c99 mode. I understand that I can set Heap_size to 0. However, what confuses me is, why is the heap still set to 2048 (or used at all), even though I do not change the code to use dynamic memory allocation. What I understand is, heap is automatically set to 0 in compile time if I do not use dynamic mem allocation or use MicroLib, as what has been applied in my code before modification. Or do I understand it wrong?

Thank you!

Parents Reply Children
  • I add some more information in question about this to make it clearer

  • I don't quite understand what you mean by "heap is automatically set to 0 in compile time". I've seen heap controlled in two ways. One was in the startup .s file such as the one you mention. I've also seen the IDE allow you to specify the heap size like IAR does when you edit the linker control file. Is setting the heap size in the startup .s file not working for you? (it sounds like it is)

  • I mean the compiler (or somewhere in sdk, not sure) knows automatically that I don't use dynamic memory alloc, and set the heap size to 0 automatically. Because my last working version do not use heap at all, even though I did not changed the default linker control file or heap size in IDE. I know it didn't use heap because I tested this by manually edit linker control file, such that defined or not defined, the heap size always 0, and the map still show startup_nrf51 use 2kB (same size as before editing), which is the full size of stack. So, no heap in those 2kB in the first place.

    About setting the heap size, yes it works for me (succesfully compiled). however, I would like to know what triggers this sudden heap usage, as the behaviour is odd for me.

  • I don't know of a tool chain that automatically determines you need heap allocated let alone what size it is. It is something you need to specify either by the startup .s file or the IDE. Did you obtain a new version of your startup file that had the heap set to 2K? That's the only thing I could think of.

Related