Search code examples
cmemorycsr

CSR1000 allocate memory


I'm currently playing around with the CSR 1000 chip and I wanted to allocate memory. I tried using malloc but the compiler tells me:

undefined reference to `malloc'

I assume that is because gcc is run with -nostdlib parameter

So please could somebody with CSR uEnergy SDK experience, tell me why I can't allocate memory, and how I should do it instead??


Solution

  • If there is an SDK bundled with that chip that provides basic routines for memory allocation then use those, alternatively you can write your own allocator or use an existing one off of the web (with some fiddling).

    As a quick solution you can probably mark a region in memory using a modified linker script or by using the gcc 'section' attribute (more here) and then use that as your heap arena in your malloc allocator.

    A very simple allocator would not keep any accounting information such as headers/footers but rather allocate linearly one region after another (free-ing would essentially be a no-op in this case), this won't get you far but you will be able to run simple programs.

    You probably want something more sophisticated, you could also look into implementing some kind of memory pool or any of the standard allocation algorithms.

    The classic book The C Programming Language by Dennis Ritchie and Brian Kernighan provides a simple memory allocator if I re-call correctly. You may want to have a look at that.