Microchip® Advanced Software Framework

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/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 "netif/ppp_oe.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().

Referenced by pbuf_free(), tcpip_callback_with_block(), tcpip_callbackmsg_delete(), tcpip_input(), and tcpip_thread().

void memp_init ( void  )

Initialize this module.

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

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

Referenced by lwip_init().

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

Referenced by mem_free(), mem_trim(), memp_free(), pbuf_free(), and pbuf_ref().

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_DBG_LEVEL_SERIOUS
Definition: debug.h:47
#define MEMP_DEBUG
MEMP_DEBUG: Enable debugging in memp.c.
Definition: opt.h:1993
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:95
return memp = memp_tab[type]

Referenced by memp_free(), and memp_init().

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.