码迷,mamicode.com
首页 > 其他好文 > 详细

lwip的内存管理

时间:2018-04-21 16:16:53      阅读:408      评论:0      收藏:0      [点我收藏+]

标签:color   var   全局   pre   ack   prot   esc   define   isp   

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的内存管理

标签:color   var   全局   pre   ack   prot   esc   define   isp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!