首页 > 其他 > 详细

lwip的内存管理

时间:2018-04-21 15:56:07      阅读:225      评论:0      收藏:0      [点我收藏+]

lwip可以不用malloc,而完全用pool,全用全局变量,没看明白怎么实现的。

#if LWIP_NETCONN || LWIP_SOCKET
LWIP_MEMPOOL(NETBUF,         MEMP_NUM_NETBUF,          sizeof(struct netbuf),         "NETBUF")
LWIP_MEMPOOL(NETCONN,        MEMP_NUM_NETCONN,         sizeof(struct netconn),        "NETCONN")
#endif /* LWIP_NETCONN || LWIP_SOCKET */

 

1 #define LWIP_MEMPOOL(name,num,size,desc) LWIP_MEMPOOL_DECLARE(name,num,size,desc)

 

 1 /**
 2  * @ingroup mempool
 3  * Declare a private memory pool
 4  * Private mempools example:
 5  * .h: only when pool is used in multiple .c files: LWIP_MEMPOOL_PROTOTYPE(my_private_pool);
 6  * .c:
 7  *   - in global variables section: LWIP_MEMPOOL_DECLARE(my_private_pool, 10, sizeof(foo), "Some description")
 8  *   - call ONCE before using pool (e.g. in some init() function): LWIP_MEMPOOL_INIT(my_private_pool);
 9  *   - allocate: void* my_new_mem = LWIP_MEMPOOL_ALLOC(my_private_pool);
10  *   - free: LWIP_MEMPOOL_FREE(my_private_pool, my_new_mem);
11  *
12  * To relocate a pool, declare it as extern in cc.h. Example for GCC:
13  *   extern u8_t __attribute__((section(".onchip_mem"))) memp_memory_my_private_pool[];
14  */
15 #define LWIP_MEMPOOL_DECLARE(name,num,size,desc) 16   LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); 17     18   LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(memp_stats_ ## name) 19     20   static struct memp *memp_tab_ ## name; 21     22   const struct memp_desc memp_ ## name = { 23     DECLARE_LWIP_MEMPOOL_DESC(desc) 24     LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(memp_stats_ ## name) 25     LWIP_MEM_ALIGN_SIZE(size), 26     (num), 27     memp_memory_ ## name ## _base, 28     &memp_tab_ ## name 29   };
30 
31 #endif /* MEMP_MEM_MALLOC */

 

1 #ifndef LWIP_DECLARE_MEMORY_ALIGNED
2 #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
3 #endif

lwip的内存管理

原文:https://www.cnblogs.com/yanhc/p/8901619.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!