[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] about alignment issues.

From: Curt McDowell
Subject: Re: [lwip-users] about alignment issues.
Date: Fri, 14 Apr 2006 09:30:46 -0700
User-agent: Mutt/

On Fri, Apr 14, 2006 at 12:43:20AM -0400, Derek Guerdon wrote:
> On Thu, 13 Apr 2006 16:16:43 -0700, Curt McDowell wrote:
> >Unions are really ugly, and I don't think they're necessary in pbuf.c.  But
> >your idea to use an embedded structure is good.  How about the following?
> >
> >struct {
> >  struct pbuf pbuf;
> >} pbuf_pool_memory[PBUF_POOL_SIZE];
> >
> >The alignment requirement of a structure is the maximum of the alignment
> >requirements of any member of the structure.  struct pbuf is intrinsically
> >aligned.
> A struct pbuf is only guaranteed to be suitably aligned for the three
> data types it contains: void*, struct pbuf*, and u16_t. There is no
> guarantee that this will result in maximum alignment.
> ...
> A union may not be aesthetically pleasing, but it can ensure that a
> u8_t array is properly aligned for another data type.


Thank you, I had missed that, not thinking that anything greater than a
pointer type would be stored in a pbuf.

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.

Curt McDowell
Broadcom Corp.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]