初级会员
- 积分
- 78
- 金钱
- 78
- 注册时间
- 2014-4-21
- 在线时间
- 12 小时
|
5金钱
Dear 亲们:
先谢谢谢。。。。。。
mem_init初始化时next设置为 mem->next = MEM_SIZE_ALIGNED; 这样的话,由于mem结构占用空间, 所以最大可分配的空间就只有MEM_SIZE_ALIGNED - SIZEOF_STRUCT_MEM;
为什么初始化时,不是这样配置了mem->next = MEM_SIZE_ALIGNED + SIZEOF_STRUCT_MEM;
ram_end = (struct mem *)(void *)&ram[MEM_SIZE_ALIGNED + SIZEOF_STRUCT_MEM];
void
mem_init(void)
{
struct mem *mem;
LWIP_ASSERT("Sanity check alignment",
(SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT-1)) == 0);
/* align the heap */
ram = (u8_t *)LWIP_MEM_ALIGN(LWIP_RAM_HEAP_POINTER);
/* initialize the start of the heap */
mem = (struct mem *)(void *)ram;
mem->next = MEM_SIZE_ALIGNED; // 为什么不是mem->next = MEM_SIZE_ALIGNED + SIZEOF_STRUCT_MEM;
mem->prev = 0;
mem->used = 0;
/* initialize the end of the heap */
ram_end = (struct mem *)(void *)&ram[MEM_SIZE_ALIGNED];//为什么不是ram_end = (struct mem *)(void *)&ram[MEM_SIZE_ALIGNED + SIZEOF_STRUCT_MEM];
ram_end->used = 1;
ram_end->next = MEM_SIZE_ALIGNED;
ram_end->prev = MEM_SIZE_ALIGNED;
/* initialize the lowest-free pointer to the start of the heap */
lfree = (struct mem *)(void *)ram;
MEM_STATS_AVAIL(avail, MEM_SIZE_ALIGNED);
if(sys_mutex_new(&mem_mutex) != ERR_OK) {
LWIP_ASSERT("failed to create mem_mutex", 0);
}
}
|
|