delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/17/13:04:19

Date: Sun, 17 Aug 1997 19:57:01 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Badman <badman AT velocity DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: Newbie Question: Speed of indirection lookups
In-Reply-To: <5t31i0$961@news.velocity.net>
Message-ID: <Pine.SUN.3.91.970817195631.14271e-100000@is>
MIME-Version: 1.0

On Fri, 15 Aug 1997, Badman wrote:

> I have a question, I got an array of stuctures, which happen to cotain
> arrays of structures which happen to contain pointers to values. I've got
> several mult's with these, and was wondering if is was faster to cache
> these within my procedure or just use stuct[x].struct2[y]->z.

AFAIK, every level of indirection requires adding an offset to an
address, and perhaps dereference that address (in case of the ->
operator).  Many compilers know to skip that computation when they
need to access the first member of a struct (which has a zero offset),
so be sure to put the most-used member first.

The best way to see what's the code that is generated to access the
data is to invoke gcc with -S option (note: it MUST be a capital S)
and examine the assembly code it emits.

> Also, how smart, or how does the optimization option work? Is there a
> limit, I useually use -O3, but I thought I saw somewhere somebody using
> -O9. 

According to the gcc docs, anything beyond -O3 is specific to the
platform where gcc runs.  In the preset version of DJGPP, any number
greater than 3 is the same as 3.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019