![]() |
Mbed OS Reference
|
Public Types | |
| enum class | Lifetime { POOL_ALLOCATED , HEAP_ALLOCATED , CONSTANT , VOLATILE } |
Public Member Functions | |
| virtual net_stack_mem_buf_t * | alloc_heap (uint32_t size, uint32_t align)=0 |
| Allocates memory buffer from the heap. | |
| virtual net_stack_mem_buf_t * | alloc_pool (uint32_t size, uint32_t align)=0 |
| Allocates memory buffer chain from a pool. | |
| net_stack_mem_buf_t * | realloc_heap (net_stack_mem_buf_t *orig_buf, uint32_t new_align, std::optional< uint32_t > new_len=std::nullopt, std::optional< uint16_t > new_header_skip_size=std::nullopt) |
| Reallocates a buffer or buffer chain as a contiguous (non-chained) heap buffer, freeing the original. | |
| virtual uint32_t | get_pool_alloc_unit (uint32_t align) const =0 |
| Get memory buffer pool allocation unit. | |
| uint32_t | get_pool_size () |
| Get memory buffer pool size. | |
| virtual void | free (net_stack_mem_buf_t *buf)=0 |
| Free memory buffer chain. | |
| virtual uint32_t | get_total_len (const net_stack_mem_buf_t *buf) const =0 |
| Return total length of a memory buffer chain. | |
| virtual void | copy_to_buf (net_stack_mem_buf_t *to_buf, const void *ptr, uint32_t len) |
| Copy from a raw buffer in memory to a memory buffer chain. | |
| virtual uint32_t | copy_from_buf (void *ptr, uint32_t len, const net_stack_mem_buf_t *from_buf) const |
| Copy from a memory buffer chain to a raw buffer in memory. | |
| virtual void | cat (net_stack_mem_buf_t *to_buf, net_stack_mem_buf_t *cat_buf)=0 |
| Concatenate two memory buffer chains. | |
| virtual net_stack_mem_buf_t * | get_next (const net_stack_mem_buf_t *buf) const =0 |
| Returns the next buffer. | |
| size_t | count_buffers (const net_stack_mem_buf_t *buf) |
| Count the number of buffers in a buffer chain. | |
| virtual void * | get_ptr (const net_stack_mem_buf_t *buf) const =0 |
| Return pointer to the payload of the buffer. | |
| virtual uint32_t | get_len (const net_stack_mem_buf_t *buf) const =0 |
| Return payload size of this individual buffer (NOT including any chained buffers) | |
| virtual void | set_len (net_stack_mem_buf_t *buf, uint32_t len)=0 |
| Sets the payload size of the buffer. | |
| virtual void | skip_header_space (net_stack_mem_buf_t *buf, int32_t amount)=0 |
| Skips (or un-skips) header space from the buffer. | |
| void | restore_header_space (net_stack_mem_buf_t *buf, const int32_t amount) |
| Restores previously skipped header space to the buffer. | |
| virtual int32_t | get_header_skip_size (net_stack_mem_buf_t *buf)=0 |
| Get the total number of header bytes that are currently being skipped. | |
| virtual Lifetime | get_lifetime (net_stack_mem_buf_t const *buf) const =0 |
| Gets the lifetime of the buffer. | |
| void | set_on_pool_space_avail_cb (mbed::Callback< void()> cb) |
| Set callback which will be called when pool space becomes available. | |
Protected Attributes | |
| mbed::Callback< void()> | onPoolSpaceAvailCallback |
| Callback which shall be called (if set) by the implementation after one or more buffer spaces become free in the pool. | |
Definition at line 55 of file NetStackMemoryManager.h.
|
strong |
Definition at line 303 of file NetStackMemoryManager.h.
|
pure virtual |
Allocates memory buffer from the heap.
Memory buffer allocated from heap is always contiguous and can be arbitrary size.
| size | Size of the memory to allocate in bytes |
| align | Memory alignment requirement in bytes |
Implemented in NanostackMemoryManager.
|
pure virtual |
Allocates memory buffer chain from a pool.
Memory allocated from pool is contiguous if size is equal or less than (aligned) allocation unit, otherwise may be chained. Will typically come from fixed-size packet pool memory.
| size | Total size of the memory to allocate in bytes |
| align | Memory alignment requirement for each buffer in bytes |
Implemented in NanostackMemoryManager.
| net_stack_mem_buf_t * realloc_heap | ( | net_stack_mem_buf_t * | orig_buf, |
| uint32_t | new_align, | ||
| std::optional< uint32_t > | new_len = std::nullopt, |
||
| std::optional< uint16_t > | new_header_skip_size = std::nullopt |
||
| ) |
Reallocates a buffer or buffer chain as a contiguous (non-chained) heap buffer, freeing the original.
Only the visible data in the source buffer is copied, not any skipped headers. Data from chained buffers will be copied.
| orig_buf | Original buffer. Will be freed whether or not the new buffer is allocated. |
| new_align | Alignment to allocate the new buffer with |
| new_len | If set, this length will be used instead of the buffer's original length |
| new_header_skip_size | If set, this header skip size will be set on the new buffer. If unset, no header skip will be set |
|
pure virtual |
Get memory buffer pool allocation unit.
Returns the maximum size of contiguous memory that can be allocated from a pool.
| align | Memory alignment requirement in bytes |
Implemented in NanostackMemoryManager.
| uint32_t get_pool_size | ( | ) |
Get memory buffer pool size.
Definition at line 123 of file NetStackMemoryManager.h.
|
pure virtual |
Free memory buffer chain.
Frees all buffers from the chained list.
| buf | Memory buffer chain to be freed. |
Implemented in NanostackMemoryManager.
|
pure virtual |
Return total length of a memory buffer chain.
Returns a total length of this buffer and any following buffers in the chain.
| buf | Memory buffer chain |
Implemented in NanostackMemoryManager.
|
virtual |
Copy from a raw buffer in memory to a memory buffer chain.
Copies data to a buffer chain. Copy operation does not adjust the lengths of the copied-to memory buffer chain, so chain total length must match the copied length.
| to_buf | Memory buffer chain to copy to |
| ptr | Pointer to data |
| len | Data length |
|
virtual |
Copy from a memory buffer chain to a raw buffer in memory.
Header skip bytes are processed, so the copy will begin AFTER the header bytes of from_buf
| len | Data length |
| ptr | Pointer to data |
| from_buf | Memory buffer chain to copy from |
|
pure virtual |
Concatenate two memory buffer chains.
Concatenates buffer chain to end of the other buffer chain. Concatenated-to buffer total length is adjusted accordingly. cat_buf must point to the start of a the chain. After concatenation to_buf's chain now owns those buffers, and they will be freed when the to_buf chain is freed.
cat_buf to have skipped header bytes.| to_buf | Memory buffer chain to concatenate to |
| cat_buf | Memory buffer chain to concatenate |
Implemented in NanostackMemoryManager.
|
pure virtual |
Returns the next buffer.
Returns the next buffer from the memory buffer chain.
| buf | Memory buffer |
Implemented in NanostackMemoryManager.
| size_t count_buffers | ( | const net_stack_mem_buf_t * | buf | ) |
Count the number of buffers in a buffer chain.
| buf | Memory buffer |
Definition at line 207 of file NetStackMemoryManager.h.
|
pure virtual |
Return pointer to the payload of the buffer.
Note that this is affected by the current header skip size (see below)
| buf | Memory buffer |
Implemented in NanostackMemoryManager.
|
pure virtual |
Return payload size of this individual buffer (NOT including any chained buffers)
Note that this is affected by the current header skip size (see below)
| buf | Memory buffer |
Implemented in NanostackMemoryManager.
|
pure virtual |
Sets the payload size of the buffer.
The allocated payload size will not change. It is not permitted to change the length of a buffer that is not the first (or only) in a chain.
Note that this is affected by the current header skip size (see below)
*Note as of Dec 2024: Different implementations (Nanostack vs LwIP) disagree about how to implement this operation. Specifically, if called on the head of a buffer chain, the LwIP implementation allows changing the length of the chain as a whole. However, the Nanostack implementation does not and only can change the length of the head buffer. For fear of breaking existing code, I do not want to change this behavior. So, if constructing a buffer chain, it is safest to set the buffer lengths first before building the chain.
| buf | Memory buffer |
| len | Payload size, must be less or equal to the allocated size |
Implemented in NanostackMemoryManager.
|
pure virtual |
Skips (or un-skips) header space from the buffer.
Skipping n bytes of header space causes the buffer's payload pointer to refer to a location n bytes after the base address of the packet buffer, and the length of the buffer to be decreased by n.
This is commonly used to skip protocol headers in network packets. For example, if you have an Ethernet frame, skipping 14 bytes of header space will cause the "start" of the packet buffer to point to the IP header instead.
Multiple calls to this function add together, so for example if you first skip 14 bytes, then -4, then 10, the result will be 20 total bytes of skipped header.
| buf | Buffer to operate on. |
| amount | Amount of header space to skip. Negative values are allowed and cause previously skipped header space to be removed. |
Implemented in NanostackMemoryManager.
| void restore_header_space | ( | net_stack_mem_buf_t * | buf, |
| const int32_t | amount | ||
| ) |
Restores previously skipped header space to the buffer.
This function is the inverse of skip_header_space().
| buf | Buffer to operate on. |
| amount | Amount of header space to skip. Negative values are allowed and cause previously skipped header space to be removed. |
Definition at line 289 of file NetStackMemoryManager.h.
|
pure virtual |
Get the total number of header bytes that are currently being skipped.
This is the aggregate result of all skip_header_space() / restore_header_space() calls.
| buf | Buffer to operate on. |
Implemented in NanostackMemoryManager.
|
pure virtual |
| void set_on_pool_space_avail_cb | ( | mbed::Callback< void()> | cb | ) |
Set callback which will be called when pool space becomes available.
| cb | Callback to call |
Definition at line 325 of file NetStackMemoryManager.h.
|
protected |
Callback which shall be called (if set) by the implementation after one or more buffer spaces become free in the pool.
This is used by zero-copy Ethernet MACs as a hint that now is a good time to allocate fresh buffers off the pool into Ethernet descriptors. It is legal to call this function if you aren't totally sure new memory is available – the mac will try to allocate more buffers, and if it can't, oh well. However, it is not legal for memory to become available without a call to this function. Such a situation might lead to a lockup of the MAC due to not having memory allocated for Rx.
Definition at line 65 of file NetStackMemoryManager.h.