init_dynamic_memory() question

2010-08-20
2013-03-12
  • Brennen Ball
    Brennen Ball
    2010-08-20

    I saw that at one time, init_dynamic_memory() was required to be called from the user's code, but now it is called automatically within malloc().  It uses the variable _sdcc_heap in _heap.c, whose size is determined by #define HEAP_SIZE in the same file.  The problem I have with this is that the default value of HEAP_SIZE is 1024, which is the entire RAM on my chip (nRF24LE1).  I really dislike having to rebuild compilers, as it makes it harder for anyone using my code.  Is there any possible way to override the current way of using init_dynamic_memory() to go back to the old way of calling it manually *WITHOUT* modifying SDCC's source code?  I'm assuming not, but I figured I'd ask anyway.  :-)

     
  • Maarten Brock
    Maarten Brock
    2010-08-23

    You don't need to modify SDCC's source code. You just need to copy _heap.c into your project and compile it there with the wanted size. The linker will use your explicitly linked object instead of importing the default from the library.

    But if you have only 1024 bytes of XRAM I recommend to try and do without malloc completely.