|
liblightmodbus 3.0
A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library
|
Liblightmodbus allows users to define their custom functions for memory management. This functionality is provided with embedded systems in mind.
The user defined allocator is a function compatible with ModbusAllocator pointer type.
The allocator function must meet the following requirements:
size is 0, the memory allocated for the buffer (buffer->data) must be freed (if possible) and the buffer->data pointer should be set to NULL.size is not 0, buffer->data should be set to point to a memory block of at least size bytes. If such block cannot be allocated, the allocator must return MODBUS_ERROR_ALLOC and free memory block pointed to by current buffer->data value. Consequently, buffer->data should be set to NULL.Additionally:
size is greater than zero will be reported by the library as MODBUS_GENERAL_ERROR(ALLOC).size is 0. Then, errors reported by the allocator may or may not be reported by the library interface. This behavior might change depending on the context and in future versions of the library.void *context argument.An example of a custom allocator relying only on statically allocated memory:
One could also implement an allocator allocating memory from different statically allocated buffers based on buffer pointers, using the user context for bookkeeping.