[mem] Remove useless code And Update mem documentation

This commit is contained in:
wdfk-prog 2024-04-18 21:58:09 +08:00 committed by Meco Man
parent 9229aee1d7
commit d8dcc05174
4 changed files with 23 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -43,7 +43,13 @@ Any or none of these memory heap management algorithms can be chosen when the sy
### Small Memory Management Algorithm ### Small Memory Management Algorithm
The small memory management algorithm is a simple memory allocation algorithm. Initially, it is a large piece of memory. When a memory block needs to be allocated, the matching memory block is segmented from the large memory block, and then this matching free memory block is returned to the heap management system. Each memory block contains data head for management use through which the used block and the free block are linked by a doubly linked list, as shown in the following figure: The small memory management algorithm is a simple memory allocation algorithm. Initially, it is a large piece of memory. When a memory block needs to be allocated, the matching memory block is segmented from the large memory block, and then this matching free memory block is returned to the heap management system. Each memory block contains data head for management use through which the used block and the free block are linked by a doubly linked list.
**Use this implementation before 4.1.0**
As shown in the following figure:
![Small Memory Management Working Mechanism Diagram](figures/08smem_work.png) ![Small Memory Management Working Mechanism Diagram](figures/08smem_work.png)
@ -55,6 +61,22 @@ Each memory block (whether it is an allocated memory block or a free memory bloc
The performance of memory management is mainly reflected in the allocation and release of memory. The small memory management algorithm can be embodied by the following examples. The performance of memory management is mainly reflected in the allocation and release of memory. The small memory management algorithm can be embodied by the following examples.
**4.1.0 and later use this implementation**
As shown in the following figure:
![](figures/08smem_work4.png)
**Heap Start**: The heap head address stores memory usage information, the heap head address pointer, the heap end address pointer, the minimum heap free address pointer, and the memory size.
Each memory block (whether it is an allocated memory block or a free memory block) contains a data head, including:
**pool_ptr**: Small memory object address. If the last bit of the memory block is 1, it is used. If the last bit of the memory block is 0, it is not used. When used, the structure members of the small memory algorithm can be quickly obtained by calc.
As shown in the following figure, the free list pointer lfree initially points to a 32-byte block of memory. When the user thread wants to allocate a 64-byte memory block, since the memory block pointed to by this lfree pointer is only 32 bytes and does not meet the requirements, the memory manager will continue to search for the next memory block. When the next memory block with 128 bytes is found, it meets the requirements of the allocation. Because this memory block is large, the allocator will split the memory block, and the remaining memory block (52 bytes) will remain in the lfree linked list, as shown in the following table which is after 64 bytes is allocated. As shown in the following figure, the free list pointer lfree initially points to a 32-byte block of memory. When the user thread wants to allocate a 64-byte memory block, since the memory block pointed to by this lfree pointer is only 32 bytes and does not meet the requirements, the memory manager will continue to search for the next memory block. When the next memory block with 128 bytes is found, it meets the requirements of the allocation. Because this memory block is large, the allocator will split the memory block, and the remaining memory block (52 bytes) will remain in the lfree linked list, as shown in the following table which is after 64 bytes is allocated.
![Small Memory Management Algorithm Linked List Structure Diagram 1](figures/08smem_work2.png) ![Small Memory Management Algorithm Linked List Structure Diagram 1](figures/08smem_work2.png)

View File

@ -15,9 +15,6 @@
struct rt_small_mem_item struct rt_small_mem_item
{ {
rt_ubase_t pool_ptr; /**< small memory object addr */ rt_ubase_t pool_ptr; /**< small memory object addr */
#ifdef ARCH_CPU_64BIT
rt_uint32_t resv;
#endif /* ARCH_CPU_64BIT */
rt_size_t next; /**< next free item */ rt_size_t next; /**< next free item */
rt_size_t prev; /**< prev free item */ rt_size_t prev; /**< prev free item */
#ifdef RT_USING_MEMTRACE #ifdef RT_USING_MEMTRACE

View File

@ -59,9 +59,6 @@
struct rt_small_mem_item struct rt_small_mem_item
{ {
rt_ubase_t pool_ptr; /**< small memory object addr */ rt_ubase_t pool_ptr; /**< small memory object addr */
#ifdef ARCH_CPU_64BIT
rt_uint32_t resv;
#endif /* ARCH_CPU_64BIT */
rt_size_t next; /**< next free item */ rt_size_t next; /**< next free item */
rt_size_t prev; /**< prev free item */ rt_size_t prev; /**< prev free item */
#ifdef RT_USING_MEMTRACE #ifdef RT_USING_MEMTRACE
@ -85,8 +82,6 @@ struct rt_small_mem
rt_size_t mem_size_aligned; /**< aligned memory size */ rt_size_t mem_size_aligned; /**< aligned memory size */
}; };
#define HEAP_MAGIC 0x1ea0
#define MIN_SIZE (sizeof(rt_ubase_t) + sizeof(rt_size_t) + sizeof(rt_size_t)) #define MIN_SIZE (sizeof(rt_ubase_t) + sizeof(rt_size_t) + sizeof(rt_size_t))
#define MEM_MASK ((~(rt_size_t)0) - 1) #define MEM_MASK ((~(rt_size_t)0) - 1)