lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] The purpose of structure packing


From: Jonathan Larmour
Subject: Re: [lwip-users] The purpose of structure packing
Date: Wed, 12 Dec 2007 19:30:45 +0000
User-agent: Thunderbird 1.5.0.12 (X11/20070530)

Grubb, Jared wrote:
> ip_hdr._ttl_proto is 16 bits long, but this includes both the TTL and
> the protocol bits.

Indeed.

Muhamad Ismail wrote:
> My question is what is the purpose of structure packing. I at first
> thought lwip requires it to spare memory and keep alignment problem
> away, and since I dont have much of those problem I removed all of
> my structure packing macros.

Just because an architecture is byte addressable, doesn't mean that the
compiler will lay out a struct without any padding. Even when something is
byte addressable, it is often faster to maintain words (or half words etc.)
on word (or half word) boundaries, and compilers seek to do this. For
example with this struct:

struct foo {
  char c;
  int i;
};

on most architectures, a compiler will align i to some boundary because
that means later you can load an int with a single load word instruction,
rather than anything more complicated. Even if an architecture permitted an
unaligned access in a single instruction, it would potentially require two
underlying memory accesses to the RAM chips, so would take longer - again
compiler's will try and keep things faster.

Or another quicker way to look at it is that since changing it clearly
didn't work,  your assumptions can't be right ;-).

Jifl
-- 
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------       Opinions==mine




reply via email to

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