🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2483

Re: pointers for speed

#2483
From: Dave P. Schaumann
Date: Mon, 25 Feb 1991 23:36
23 lines
1404 bytes
In article <1998@gold.gvg.tek.com> shaunc@gold.gvg.tek.com (Shaun Case) writes:
>I know that when you repeatedly access something like
>
>foo.a.b.c.d[11].value
>
>it is better to declare a (register) pointer, assign it the address
>of foo.a.b.c.d[11].value, and do manipulations on that, since it
>is faster.

Oh really?  Seems to me that &foo.a.b.c.d[0] is a constant that can be
computed *at compile time*.  That means that (unless your comiler is
totally brain-dead) accessing foo.a.b.c.d[0] should be as fast as accessing
a normal element of an array of the same type.

Yes, calculating the address does take a bit longer, but that calculation is
done once by the compiler, and is known forever more.

Now, if you had foo->a->b->c->d, you would certainly want to keep the
address of d in a variable, rather than indirecting 4 times.

-- 
Dave Schaumann      | Is this question undecidable?
dave@cs.arizona.edu |
Technical Details
Message-ID: <955@caslon.cs.arizona.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ncar!noao!arizona!dave
References: <1998@gold.gvg.tek.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ncar!noao!arizona!dave
From: dave@cs.arizona.edu (Dave P. Schaumann)
Newsgroups: comp.std.c
Subject: Re: pointers for speed
Message-ID: <955@caslon.cs.arizona.edu>
Date: 25 Feb 91 23:36:24 GMT
References: <1998@gold.gvg.tek.com>
Organization: U of Arizona CS Dept, Tucson
Lines: 23