4、uCOS-ii中的内存管理
上图中将一个内存分区和一个内存控制块结构体相关联,当系统定义多个内存分区时(由OS_MAX_MEM_PART定义),系统会初始化空内存控制块链表,其示意图如下:
OS_MEM *OSMemFreeList;
OS_MEM OSMemTbl[OS_MAX_MEM_PART];
typedef struct os_mem {
void *OSMemAddr;
void *OSMemFreeList;
INT32U OSMemBlkSize;
INT32U OSMemNBlks;
INT32U OSMemNFree;
} OS_MEM;
typedef struct os_mem_data {
void *OSAddr;
void *OSFreeList;
INT32U OSBlkSize;
INT32U OSNBlks;
INT32U OSNFree;
INT32U OSNUsed;
} OS_MEM_DATA;
一个内存分区是如何将其各个内存块连接在一起的,定义如下:
INT8U *pblk;
void **plink;
plink = (void **)addr;
pblk = (INT8U *)((INT32U)addr + blksize);
for (i = 0; i < (nblks - 1); i++) {
*plink = (void *)pblk;
plink = (void **)pblk;
pblk = (INT8U *)((INT32U)pblk + blksize);
}
*plink = (void *)0;