Memory Management

Hello,

I am curious as to how memory management works. Searching the code for "void free(" returns two implementations. One implements the function in the native port as a wrapper of the systems implementations (?) and the other does nothing (found in malloc.h in the folder oneway-malloc and implemented in oneway-malloc.c).

Is there another implementation I have overlooked or is there no way to free memory on boards?

Thanks Raphael

Hi Raphael,

I am curious as to how memory management works. Searching the code for "void free(" returns two implementations. One implements the function in the native port as a wrapper of the systems implementations (?) and the other does nothing (found in malloc.h in the folder oneway-malloc and implemented in oneway-malloc.c).

Yes, the native "implementation" just wraps the system implementation.

Is there another implementation I have overlooked or is there no way to free memory on boards?

Please have a look at Static vs Dynamic Memory · RIOT-OS/RIOT Wiki · GitHub

Cheers, Ludwig

Hi Raphael, for the native-stuff you have to ask Ludwig for the specifics as to of why, but most of the hosts system’s implementation of standard functions are wrapped. I think this was because our POSIX interface would otherwise colide with the system’s POSIX interface. As for the other boards I’m refrasing only what I’ve been told, so please correct me if I’m wrong, anyone: newlib provides free() for most of our ARM boards (provided sbrk() is implemented as a syscall). For msp430 there is currently only oneway-malloc available and for AVR I’m not sure about the implementation. Maybe Hinnerk can shed some light on this :-).

Cheers, Martine

Hi,

Hi,

thanks for the answers! Since I am interested in the stm32f4discovery, everything should be fine?

Raphael

Hi Raphael,

Hello Martine,

Was that a question? I guess it was… As far as its documentation goes free is not possible by now on stm32f4: https://github.com/RIOT-OS/RIOT/blob/master/cpu/stm32f4/syscalls.c#L122

that was indeed a question and a bit of an assumption. The previously mentioned wiki entry does suggest that malloc and free are working indeed [1].

Are there plans to implement this? I couldn’t find anything in the open issues or PRs regarding this topic.

Raphael

[1] Static vs Dynamic Memory · RIOT-OS/RIOT Wiki · GitHub

I’m not sure what that documentation is based on though, running tests/malloc will allocate and free all available memory just fine. However, beware of memory fragmentation. Benjamin

Hello Benjamin,

I'm not sure what that documentation is based on though, running tests/malloc will allocate and free all available memory just fine.

may I ask how you tested this?

Raphael

I just flashed the test to my board (not stm32f4discovery, but _sbrk_r is the same). Just run make BOARD=stm32f4discovery flash term and you should see it allocating memory till malloc() returns 0, then freeing it all again, ad infinitum.

Benjamin

Hello,

ah, sure. I did not connect "tests/malloc" to the path in RIOT. Thanks for the clarification.

Raphael