Microchip® Advanced Software Framework

dev/src/core/memp.c File Reference

Dynamic pool memory manager.

lwIP has dedicated pools for many structures (netconn, protocol control blocks, packet buffers, ...). All these pools are managed here.

#include "lwip/opt.h"
#include "lwip/memp.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
#include "lwip/raw.h"
#include "lwip/tcp_impl.h"
#include "lwip/igmp.h"
#include "lwip/api.h"
#include "lwip/api_msg.h"
#include "lwip/sockets.h"
#include "lwip/tcpip.h"
#include "lwip/sys.h"
#include "lwip/timers.h"
#include "lwip/stats.h"
#include "netif/etharp.h"
#include "lwip/ip_frag.h"
#include "lwip/snmp_structs.h"
#include "lwip/snmp_msg.h"
#include "lwip/dns.h"
#include "lwip/netdb.h"
#include "netif/ppp/ppp.h"
#include "netif/ppp/pppoe.h"
#include "netif/ppp/pppol2tp.h"
#include "lwip/nd6.h"
#include "lwip/ip6_frag.h"
#include "lwip/mld6.h"
#include <string.h>
#include "lwip/memp_std.h"

Data Structures

struct  memp
 

Macros

#define LWIP_MEMPOOL(name, num, size, desc)   LWIP_MEM_ALIGN_SIZE(size),
 
#define LWIP_MEMPOOL(name, num, size, desc)   (num),
 
#define LWIP_MEMPOOL(name, num, size, desc)   + ( (num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size) ) )
 
#define MEMP_ALIGN_SIZE(x)   (LWIP_MEM_ALIGN_SIZE(x))
 
#define MEMP_SIZE   0
 

Functions

 if (memp!=NULL)
 
 LWIP_ERROR ("memp_malloc: type < MEMP_MAX",(type< MEMP_MAX), return NULL;)
 
void memp_free (memp_t type, void *mem)
 Put an element back into its pool. More...
 
void memp_init (void)
 Initialize this module. More...
 
 MEMP_STATS_INC (err, type)
 
void * SYS_ARCH_DECL_PROTECT (old_level)
 Get an element from a specific pool. More...
 
 SYS_ARCH_PROTECT (old_level)
 
 SYS_ARCH_UNPROTECT (old_level)
 

Variables

 else
 
 memp = memp_tab[type]
 
static u8_t memp_memory [MEM_ALIGNMENT-1#define LWIP_MEMPOOL(name, num, size, desc)]
 This array holds a textual description of each pool. More...
 
static const u16_t memp_num [MEMP_MAX]
 This array holds the number of elements in each pool. More...
 
static const u16_t memp_sizes [MEMP_MAX]
 This array holds the element sizes of each pool. More...
 
static struct mempmemp_tab [MEMP_MAX]
 This array holds the first free element of each pool. More...
 

#define LWIP_MEMPOOL (   name,
  num,
  size,
  desc 
)    LWIP_MEM_ALIGN_SIZE(size),
#define LWIP_MEMPOOL (   name,
  num,
  size,
  desc 
)    (num),
#define LWIP_MEMPOOL (   name,
  num,
  size,
  desc 
)    + ( (num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size) ) )
#define MEMP_ALIGN_SIZE (   x)    (LWIP_MEM_ALIGN_SIZE(x))
#define MEMP_SIZE   0

Referenced by if(), memp_free(), and memp_init().

LWIP_ERROR ( )
void memp_free ( memp_t  type,
void *  mem 
)

Put an element back into its pool.

Parameters
typethe pool where to put mem
memthe memp element to free

References LWIP_ASSERT, MEM_ALIGNMENT, memp, MEMP_SIZE, MEMP_STATS_DEC, memp::next, NULL, SYS_ARCH_DECL_PROTECT, SYS_ARCH_PROTECT, and SYS_ARCH_UNPROTECT.

void memp_init ( void  )

Initialize this module.

Carves out memp_memory into linked lists for each pool-type.

References LWIP_MEM_ALIGN, max, memp, MEMP_MAX, memp_memory, MEMP_OVERFLOW_CHECK, MEMP_SIZE, memp_sizes, MEMP_STATS_AVAIL, memp::next, and NULL.

MEMP_STATS_INC ( err  ,
type   
)
void* SYS_ARCH_DECL_PROTECT ( old_level  )

Get an element from a specific pool.

Parameters
typethe pool to get an element from

the debug version has two more parameters:

Parameters
filefile name calling this function
linenumber of line where this function is called
Returns
a pointer to the allocated memory or a NULL pointer on error
SYS_ARCH_PROTECT ( old_level  )
SYS_ARCH_UNPROTECT ( old_level  )

else
Initial value:
{
LWIP_DEBUGF(MEMP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("memp_malloc: out of memory in pool %s\n", memp_desc[type]))
#define LWIP_DEBUGF(debug, message)
Definition: src/include/lwip/debug.h:95
#define MEMP_DEBUG
MEMP_DEBUG: Enable debugging in memp.c.
Definition: src/include/lwip/opt.h:1993
#define LWIP_DBG_LEVEL_SERIOUS
Definition: src/include/lwip/debug.h:47
return memp = memp_tab[type]
u8_t memp_memory[MEM_ALIGNMENT-1#define LWIP_MEMPOOL(name, num, size, desc)]
static

This array holds a textual description of each pool.

This is the actual memory used by the pools (all pools in one big block).

Referenced by memp_init().

const u16_t memp_num[MEMP_MAX]
static
Initial value:
= {
#define LWIP_MEMPOOL(name,num,size,desc)
}

This array holds the number of elements in each pool.

const u16_t memp_sizes[MEMP_MAX]
static
Initial value:
= {
#define LWIP_MEMPOOL(name,num,size,desc)
}

This array holds the element sizes of each pool.

Referenced by memp_init().

struct memp* memp_tab[MEMP_MAX]
static

This array holds the first free element of each pool.

Elements form a linked list.