msgpack / msgpack-c

MessagePack implementation for C and C++ / msgpack.org[C/C++]
Other
2.95k stars 872 forks source link

msgpack-c with stack only #789

Open wiesener opened 5 years ago

wiesener commented 5 years ago

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.

redboltz commented 5 years ago

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.

redboltz commented 5 years ago

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

redboltz commented 5 years ago

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.

redboltz commented 5 years ago

Here are some memory allocator libraries: