RTOS memory use - use of variable length memory blocks

RTOS memory use - use of variable length memory blocks

overview

variable length memory block

A variable-length memory block refers to applying for a memory block according to the required length when using it. Variable-length storage blocks are usually managed through a linked list:
insert image description here

Advantages of using variable-length memory blocks:

1) Space of any size can be allocated.

Disadvantages of using variable-length memory blocks:

1) The allocation and recycling efficiency is low, and it is easy to form memory fragmentation.

How to choose a suitable memory block:

1) When the memory allocation size requirements are known, or at least the maximum value is known, it is recommended to use fixed-length memory blocks.

2) When the memory allocation size requirement is unknown, or the memory block size needs to be changed frequently, it is recommended to use variable-length memory blocks.

Requirements and function analysis

Similar to the previous section, the example sets up a simple producer-consumer model. Among them, Task1 is responsible for producing data, and then sending the data to Task2 through the queue, and Task2 is responsible for receiving the data:

insert image description here

Assume that there are three types of data length requirements between Task1 and Task2: 8bytes, 10bytes, and 20bytes. The example uses variable-length storage blocks to meet the storage requirements of three lengths of data, and each time applies for the required length of memory space to store the data to be sent.

v_v

Guess you like

Origin blog.csdn.net/wangyx1234/article/details/128521755