[riot-devel] Oneway-Malloc

Oleg Hahm oliver.hahm at inria.fr
Tue Aug 9 21:27:39 CEST 2016

Hi Sam!

On Tue, Aug 09, 2016 at 12:01:08PM -0700, Sam Kumar wrote:
> I noticed that there is a "oneway-malloc" module in RIOT OS. It appears to
> be a thin wrapper around sbrk that only supports allocating memory, not
> freeing it.

This is correct. It was originally introduced for MSP430 platforms.

> I am doing some development using RIOT OS, and dynamic memory allocation
> would be useful to me. Is there already a module that implements dynamic
> memory allocation suitable for general-purpose use in the kernel and in
> user programs?

Dynamic memory allocation is usually a bad idea for embedded systems (see for
instance https://www.quora.com/Why-is-malloc-harmful-in-embedded-systems).
Within kernel context it MUST be completely avoided.

If you really need dynamic memory allocation, you can either use the TLSF
package [1] or use a simple memory manager that uses a static memory pool like
memmgr [2]. TLSF is O(1), but works only on 32 bit platforms.

> If such a module does not already exist, I am willing to contribute a
> lightweight implementation of malloc, realloc, calloc, and free to replace
> the oneway-malloc module.

This could be a good idea indeed. :) I once had the above cited memmgr as
package in one of my private branches, but I guess I haven't pushed it to
Github. However, creating this package didn't take longer than half an hour.


[1] https://github.com/RIOT-OS/RIOT/tree/master/pkg/tlsf
[2] https://github.com/eliben/code-for-blog/tree/master/2008/memmgr

The worst thing about Perl jokes is that next morning you can't understand why
they seemed so funny.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.riot-os.org/pipermail/devel/attachments/20160809/66c6952f/attachment.sig>

More information about the devel mailing list