如何设置lwip的最大socket数和消耗的内存

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-17 08:11   69   0


参考老衲五木的博客http://blog.sina.com.cn/s/blog_62a85b950101am5d.html

  1. 如何更改lwip的最大socket.

    修改lwipopts.h中的 MEMP_NUM_NETCONN

/**

*MEMP_NUM_NETCONN: the number of struct netconns.

*(only needed if you use the sequential API, like api_lib.c)

*/

#ifndef MEMP_NUM_NETCONN

#define MEMP_NUM_NETCONN (13)// zbdchange 13 <- 8

#endif

  1. 如何精简lwip消耗的内存.

修改lwipopts.h中的

/**

* MEM_SIZE:the size of the heap memory. If the application will send

* alot of data that needs to be copied, this should be set high.

*/

#ifndef MEM_SIZE

#define MEM_SIZE (48*1024)// zbdchanged <-120

#endif

/**

*TCP_MSS: TCP Maximum segment size. (default is 536, a conservative default,

*you might want to increase this.)

*For the receive side, this MSS is advertised to the remote side

*when opening a connection. For the transmit size, this MSS sets

* anupper limit on the MSS advertised by the remote host.

*/

#ifndef TCP_MSS

#define TCP_MSS 1400 // 536

#endif

/**

*MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM andPBUF_REF).

* Ifthe application sends a lot of data out of ROM (or other static memory),

*this should be set high.

*/

#ifndef MEMP_NUM_PBUF

#define MEMP_NUM_PBUF 32//16

#endif

/**

*PBUF_POOL_SIZE: the number of buffers in the pbuf pool.

*/

#ifndef PBUF_POOL_SIZE

#define PBUF_POOL_SIZE (16*3)// zbdchange 16*3 <-16*5 表示缓存池的数量

#endif

Lwip消耗的主要内存是PBUF_POOL_SIZE*TCP_MSS

所以修改这两个值可以很大的减少内存.

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP