lwip之四:pbuf

一、Pbuf

pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)

layertype

 

 

Ø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,看代码pq有关联

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做差异化处理。

 

 





posted @ 2016-05-11 18:50  自由度  Views(3143)  Comments(0)    收藏  举报