一、Pbuf
看pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
分layer和type
ØPBUF_RAM 在RAM DATA区域分配
p = (struct pbuf*)mem_malloc(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + LWIP_MEM_ALIGN_SIZE(length));
p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
offset依赖于layer
ØPBUF_POOL 在静态区域分配
p = (struct pbuf *)memp_malloc(MEMP_PBUF_POOL);
p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + (SIZEOF_STRUCT_PBUF + offset)));//1th
......
q->payload = (void *)((u8_t *)q + SIZEOF_STRUCT_PBUF);//2th-->nth,看代码p和q有关联
q->len = LWIP_MIN((u16_t)rem_len, PBUF_POOL_BUFSIZE_ALIGNED);
PBUF_POOL第一次是有offset(offset>=0)。
MEMP_PBUF_POOL是固定分配的,最后一个pool可能有空间浪费,但速度快,一般用在接收/发送数据包的场合。
ØPBUF_REF/PBUF_ROM payload由用户赋值指向
p = (struct pbuf *)memp_malloc(MEMP_PBUF);
p->payload = NULL;
代码中PBUF_REF/PBUF_ROM无差异,用户可以对PBUF_ROM做差异化处理。