Different allocators for tx and rx

Can I use two instances of CanardInstance where one is doing only tx and the other is doing only rx? I’d like to do this so I can have different memory pools for the two types of queues/sessions but I’m not sure if there’s any cross-communication that is needed at this layer.

Yes, the tx and rx pipelines are virtually independent (they only use some common configuration like the node-ID). Shouldn’t we amend the allocation functions with additional context to support this use case? We also have issue 216 that is related because it also requires additional allocation context. Perhaps:

typedef enum
{
    CANARD_MEMORY_ALLOCATION_PURPOSE_TX_QUEUE_ITEM,
    CANARD_MEMORY_ALLOCATION_PURPOSE_RX_PAYLOAD_BUFFER,
    CANARD_MEMORY_ALLOCATION_PURPOSE_RX_SESSION,
} CanardMemoryAllocationPurpose;

typedef struct
{
    CanardInstance* instance;
    CanardMemoryAllocationPurpose purpose;
    size_t size;  ///< Meaningful only during deallocation.
} CanardMemoryAllocationContext;

Then the alloc/free functions should accept a pointer to const CanardMemoryAllocationContext instead of the canard instance.

This just adds another branch into the allocation logic. Why not define an allocator structure with alloc/dealloc function pointers then have three allocators on the 'ard structure. It’d work fine if the user just used the same allocator where they don’t care but allows for more granularity where they would.

typedef struct
{
    CanardMemoryAllocate memory_allocate;
    CanardMemoryFree memory_free;
} CanardMemoryResoruce;

struct CanardInstance
{
  ...
    CanardMemoryResoruce tx_queue_item_allocator;
    CanardMemoryResoruce rx_session_allocator;
    CanardMemoryResoruce rx_payload_buffer_allocator;
};
1 Like

okay