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?
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?
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 :-).
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
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.