The wakaama library allows to override the alloc/free functions. It is not very fine grained control though, as some allocations are just small strings (that basically never change), some are for various sized transactions, some for huge block1 data.
All general heap usage should disappear.
Receiving
It should not be necessary to allocate heap memory at all for receiving.
Sending
Because the client library is restricted to UDP usage, the network MTU defines the maximum packet size. On top of that, for most packets the final size can be precomputed or determined at build time (C++11/14 constexpr). Transactions should not use the general heap directly.
The transaction class should get an own new/delete override and two memory strategies should be delivered: A pool allocator with two pools (one huge for request-all, one small for average object requests) and a heap allocator.
Block1
It can be assumed that only one Block1 data packet is on the wire at any time. The block1 class should use the general heap directly.
The block1 class should get an own new/delete override and two memory strategies should be delivered: A pool allocator with a one slot pool and a heap allocator.
Strings
Strings are used for
describing the lwm2m device to a server (the lwm2m device object)
or for connection details (server URI, dtls PSK/x509).
Most of the time string literals will be used, optimize for this use case.
Remove all strdup() calls. The lwm2m server object gets read-only with this change. If an API user wants a modifiable lwm2m server object, he need to roll out his own.
Adding/Removing a server
Instead of passing arguments to an add_server function, that allocates memory to create a new list entry and inserts all those arguments, the user should be requested to create a ServerConnection object that implements a linked list entry interface and is passed to the library.
Necessary allocations and memory management is moved to the users obligations.
The wakaama library allows to override the alloc/free functions. It is not very fine grained control though, as some allocations are just small strings (that basically never change), some are for various sized transactions, some for huge block1 data.
All general heap usage should disappear.
Receiving
It should not be necessary to allocate heap memory at all for receiving.
Sending
Because the client library is restricted to UDP usage, the network MTU defines the maximum packet size. On top of that, for most packets the final size can be precomputed or determined at build time (C++11/14 constexpr). Transactions should not use the general heap directly.
Block1
It can be assumed that only one Block1 data packet is on the wire at any time. The block1 class should use the general heap directly.
Strings
Strings are used for
Most of the time string literals will be used, optimize for this use case. Remove all
strdup()
calls. The lwm2m server object gets read-only with this change. If an API user wants a modifiable lwm2m server object, he need to roll out his own.Adding/Removing a server
Instead of passing arguments to an add_server function, that allocates memory to create a new list entry and inserts all those arguments, the user should be requested to create a ServerConnection object that implements a linked list entry interface and is passed to the library.
Necessary allocations and memory management is moved to the users obligations.