Hi everyone
Just to make it clear from the beginning, im forced to use a heap allocator not because I wish to, but because we have to rely on libraries that , unfortunately, rely on it and would simply not work without them.
A great example is Any SSL/TLS library out there.
Mbedtls forces you to use heap as well as wolfssl. Only other option is sometimes stacks in the size of half of the chips ram.
Now to the point.
From all the reading that I've don't on the forums and looking at chibios code ( which is probably the cleanest codebase I've ever seen ) my understanding is :
1. Chibios default heap allocator is suitable when a simple heap usage is needed , it doesn't have memory coalescence management so memory fragmentation could be a problem
2. I studied the options in chcfg.h called CH_CFG_MALLOC_HEAP I believe which should just put wrappers under standard libc heap calls but doing a search found that this macro is not used anywhere
The code base I have is chibios/rt 3.1.3 and hal 4.0.2 I believe
So is there still an option to use lets say IAR dlib heap allocator wrapped in chibios for mutual exclusion like FreeRtos does it for example or there is a better way?
Again, I'm not a big malloc fN, but sometimes there is no choice and memory pools don't cut it either
Need advice on using the heap
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Need advice on using the heap
Hi,
That option is obsolete ans should not be in chconf.h any more, wrapping the system allocator is no more sufficient because system requirements. In RT 4.0 there is an enhanced allocator able to return arbitrarily aligned blocks, that is not possible using malloc().
About fragmentation, any allocator is subject to that unless a garbage collector is implemented. ChibiOS allocator merges adjacent blocks on free(), of course this cannot prevent fragmentation.
Giovanni
That option is obsolete ans should not be in chconf.h any more, wrapping the system allocator is no more sufficient because system requirements. In RT 4.0 there is an enhanced allocator able to return arbitrarily aligned blocks, that is not possible using malloc().
About fragmentation, any allocator is subject to that unless a garbage collector is implemented. ChibiOS allocator merges adjacent blocks on free(), of course this cannot prevent fragmentation.
Giovanni
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Need advice on using the heap
Hi,
RT 4.0 is already available in repository and ChibiStudio includes a workspace for it. It will be likely released in Q3. It is very compatible with RT3 so migration will be easy.
Giovanni
RT 4.0 is already available in repository and ChibiStudio includes a workspace for it. It will be likely released in Q3. It is very compatible with RT3 so migration will be easy.
Giovanni
Who is online
Users browsing this forum: No registered users and 35 guests