msgpack-c
msgpack-c copied to clipboard
msgpack-c with stack only
Hi,
is there a version of msgpack which only uses stack and no heap? We need it for a embedded medical device where heap allocation is prohibited.
Thanks C.W.
Unfortunately, msgpack-c
requires heap allocation.
msgpack-c
uses new
delete
and malloc
realloc
free
.
If you want to avoid heap allocation with msgpack-c
, write global new/delete operator to allocate from static pre-allocated array. In addition define your custom malloc
realloc
free
to do the similar thing.
That means writing custom allocator.
I guess that it doesn't match your case.
I don't know other MessagePack implementation that doen't use heap allocation.
I sent the PR #791. It supports a minimal functionality to remove malloc. Could you try this?
https://github.com/redboltz/msgpack-c/blob/minimal_allocator_support/example/c/no_malloc_c.c
https://github.com/redboltz/msgpack-c/blob/minimal_allocator_support/example/cpp03/no_malloc.cpp
my_malloc
, my_realloc
, and my_free
in my example are toy level example implementation.
Only for PoC. When you implement your custom allocator from static memory (or stack), you need to write more sophisticated implementation.
Here are some memory allocator libraries:
- https://eli.thegreenplace.net/2008/10/17/memmgr-a-fixed-pool-memory-allocator
- https://github.com/eliben/code-for-blog/tree/master/2008/memmgr
- https://github.com/lynxlynx/smalloc