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.

Cheers,
Oleg

[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.

Attachment: signature.asc
Description: PGP signature

_______________________________________________
devel mailing list
devel@riot-os.org
https://lists.riot-os.org/mailman/listinfo/devel

Reply via email to