On Fri, 14 Apr 2006 09:30:46 -0700, Curt McDowell wrote:
Still, a union is not called for:
struct {
struct pbuf pbuf;
u64_t payload[MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE) / sizeof(u64_t)];
} pbuf_pool_memory[PBUF_POOL_SIZE];
Or, if it's more pleasing, we could define a "maximal" type somewhere
and use that for payload[]. "struct mem" does that in mem.c, except it
should be defined in a header file to clean it up.
I think the latter is preferable for three reasons. First, even u64_t
isn't required to be maximally aligned under ANSI-C (although in
practice I've never seen a case where it wasn't). Second, there are
some compilers without native unsigned 64-bit integer. Third,
allocating an array of 'memory aligned types' allows targets with
limited memory to avoid allocating unused memory.
The declaration needs to be reworked a bit as the one given won't
allocate enough space when MEM_ALIGNMENT is less than 8 (e.g. if
MEM_ALIGNMENT is 4 and PBUF_POOL_SIZE is 1540, only 1536 bytes are
allocated in payload).
Something along these lines should work:
MAX_ALIGN_T
payload[(PBUF_POOL_BUFSIZE+sizeof(MAX_ALIGN_T)-1)/sizeof(MAX_ALIGN_T)];
I'd like to offer my thanks to you for addressing these issues. I
think they consumed the majority of the time I spent porting lwIP.
Getting the alignment issues fixed will be a major improvement to the
code base.