Currently i am trying to port a LWIP ( Light weight TCP/IP stack ) on embedded board.
During looking code i come up with one array declaration ( in memp.c
file) which look's me strange declaration i never seen this type of declaration past.
Although it's valid declaration but i am confusing regarding this means how much space it occupy and how can i calculate it? how LWIP_MEMPOOL
macro expanded?
Declaration looks like
/** This is the actual memory used by the pools (all pools in one big block). */
static unsigned char memp_memory[MEM_ALIGNMENT - 1
#define LWIP_MEMPOOL(name,num,size,desc) + ( (num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size) ) )
#include "memp_std.h"
];
And
/** This array holds the number of elements in each pool. */
static const unsigned int memp_num[MEMP_MAX] = {
#define LWIP_MEMPOOL(name,num,size,desc) (num),
#include "memp_std.h"
};
Now let me give you each macro defination used in above array
declaration
/* 32-bit alignment */
#define MEM_ALIGNMENT 4
#define MEMP_SIZE 0
#define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
#define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x))
MEMP_MAX
defined here
/* Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */
typedef enum {
#define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name,
#include "memp_std.h"
MEMP_MAX <--------------------//MEMP_MAX
} memp_t;
And here is memp_std.h
In memp_std.h
there are many structure name used for sizeof(struct xxx)
but i am not able to include definition for all structures. So you can assume it have some size.
Can you explain how the LWIP_MEMPOOL
macro used? how the arrays defined? how the size of that array known?