msgpack-c icon indicating copy to clipboard operation
msgpack-c copied to clipboard

msgpack-c with stack only

Open wiesener opened this issue 5 years ago • 4 comments

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.

wiesener avatar Jun 28 '19 12:06 wiesener

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 avatar Jun 28 '19 12:06 redboltz

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 avatar Jul 04 '19 07:07 redboltz

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 avatar Jul 04 '19 07:07 redboltz

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

redboltz avatar Jul 04 '19 08:07 redboltz