This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I'm writing a memory pool manager that allocates fixed-size memory blocks. My question is should I allocate my memory from the .sysmem (heap)? (i.e. set the heap a certain size at build time) is this the 'right' way to do this?
I assume I would then face competition from malloc or other routines that might try to use the heap as well. But if I don't employ malloc anywhere in my code, do i need to worry about anything? if anyone would be as kind as to shed some light on this issue i would be very grateful.
regards,
Imran
The C run-time library supplied with the compiler should support multithreading heap management. You have to configure the lock() and unlock() functions so to deal with your RTOS. If You use SYS/BIOS I suppose it is done autmatically, otherwise You have to take care of that (but if You don't use multithreading this is not necessary). For my compiler version (C66xx), the lock interface is declared in <_lock.h> and it is explained in the compier documentation
So:
- If you use SYS/BIOS or a custom lock system, you can forget about the problem and use the system heap without restriction
- If you use your custom heap and maybe other calls to malloc, in only one thread , again you have no problems
In any case, restriction apply in case of use of the system and custom heap under interrupts.
Hi Alberto,
I won't be using multi-threading, just multi-processes being shifted around in round round fashion thanks to Systick (the core's internal timer), if this makes a difference. I also forgot to mention I am using a Cortex-M3 machine (with compiler TMS470).
"In any case, restriction apply in case of use of the system and custom heap under interrupts."
could explain this a little further please? do interrupts use the heap??
Regards,
Imran
About hte interrupts: Normally the interrupts don't use the heap but it depends on your interrupt service routine (if it use it or not). In general, it is not safe to call any blocking routine (such as an malloc that use a mutex to protect against race conditions) under interrupts.
If your process call malloc(), it takes the lock (the mutex) on the heap and then it is interrupted by an interrupts and your service routine call malloc, it will block.
The difference between multi-threading, multi-processes and how the can generate race condition using the system heap depend on the your operating system.
Unfortunately I don't know the TMS470 compiler. I only know that the TI run-time library usually supply the instrument (the configurable lock and unlock routine), to make the use of the heap safe.