I ran into the same problem and the only solution I could find was to write my own malloc and free . I didn't need anything special, so I just modeled my code after it was shown in K & R's C programming language (they have a naive example, documented).
Then I created two heaps: one for internal memory and one for external memory. My stack is in a completely different memory block (CCRAM on STM32F4), so I don't need to worry about sbrk . However, I had to know the starting address of my internal SRAM heap based on data size and bss segments. This was determined from the extern characters entered by the script linker.
I have enough information about my heap to find out its current size, amount of free space, and whether there is enough continuous memory to complete the allocation. If this is not enough in the internal SRAM, it tries to use the external SRAM. If there is not enough memory, this is no different from the default malloc of memory.
I use the GNU toolchain, so I managed to use the -wrap option to override the default C library by default malloc , free , realloc and calloc (Actually malloc_r , free_r , realloc_r and calloc_r since I use newlib). Since new and delete are eventually called malloc and friends, I was able to get it to work (at least for my needs).
I'm not very sure about this, but this is the best I could do within the limits of my abilities. Examine with care.
I would be interested to know a simpler solution.
source share