Need advice on using the heap

Discussions and support about ChibiOS/RT, the free embedded RTOS.
cipher
Posts: 24
Joined: Tue May 31, 2016 10:05 pm
Has thanked: 2 times
Been thanked: 2 times

Need advice on using the heap

Postby cipher » Mon Jun 06, 2016 3:29 am

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 :(

User avatar
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

Postby Giovanni » Mon Jun 06, 2016 8:36 am

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

cipher
Posts: 24
Joined: Tue May 31, 2016 10:05 pm
Has thanked: 2 times
Been thanked: 2 times

Re: Need advice on using the heap

Postby cipher » Mon Jun 06, 2016 1:24 pm

Thank you for all the info Giovanni! When is the 4.0 kernel will be available? Any significant effort for migration from 3.x to 4.0

Thanks as always!

User avatar
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

Postby Giovanni » Mon Jun 06, 2016 1:42 pm

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

cipher
Posts: 24
Joined: Tue May 31, 2016 10:05 pm
Has thanked: 2 times
Been thanked: 2 times

Re: Need advice on using the heap

Postby cipher » Mon Jun 06, 2016 11:55 pm

Great news as always ;)


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 35 guests