Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Struct Alignment

Reply
Thread Tools

Re: Struct Alignment

 
 
Eric G.
Guest
Posts: n/a
 
      08-03-2003
Andre <(E-Mail Removed)> wrote:

> Why does gcc (or any C compiler for that matter) align structs on double
> word boundaries? And why should we align variables inside structs? One
> clear advantage could be cache utilization but isn't that possible even
> without alignment? Thanks


As I understand it, it is for efficiency purposes. When things are
aligned perfectly, the computer executing the code does far less work
when moving things around.

This used to be far more important, but computers a dreadfully fast
these days and such a technique would likely only truly be useful in
extreme computationally intensive applications...like 3D rendering,
etc..


--
== Eric Gorr ========= http://www.ericgorr.net ========= ICQ:9293199 ===
"Therefore the considerations of the intelligent always include both
benefit and harm." - Sun Tzu
== Insults, like violence, are the last refuge of the incompetent... ===
 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      08-03-2003

"Eric G." <(E-Mail Removed)> wrote in message
>
> This used to be far more important, but computers a dreadfully fast
> these days and such a technique would likely only truly be useful in
> extreme computationally intensive applications...like 3D rendering,
> etc.
>

That's only partly true. There are many programs which execute a trivial bit
of arithmetic and speed doesn't matter. However if you have constant
attrition due to no floating-point values being aligned, then you are
effectively reducing (halving maybe) the speed of the whole computer. This
is serious.
And, of course, the compiler has no way of knowing whether the code it is
compiling is speed critical, like a 3d video game, or something where speed
is unimportant, like calculating interest on mortgage repayments.


 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      08-04-2003
Malcolm wrote:

<snip>

> And, of course, the compiler has no way of knowing whether the code it is
> compiling is speed critical, like a 3d video game, or something where
> speed is unimportant, like calculating interest on mortgage repayments.


Having worked on several systems in which mortgage interest repayments are
calculated, I can assure you that speed is quite important in that area.
The process is simple at its core, of course, but the fiddly bits that
arise from legislation and indeed from "competitive edge" can be quite
time-consuming.

--
Richard Heathfield : http://www.velocityreviews.com/forums/(E-Mail Removed)
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Alignment on Struct and Global Variable? Bryan Parkoff C++ 0 04-02-2005 02:32 AM
struct and union alignment S.Tobias C Programming 67 10-04-2004 07:27 AM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
Re: Struct Alignment Jack Klein C Programming 0 08-04-2003 04:31 AM



Advertisments