[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Byte alignment



On Sat, 6 Jul 2002, Lars H. wrote:

> Helt korrekt, men... et er plads noget andet er hastighed. 
> 
> Nu uden at have testet/målt dette, så antager jeg #1) er hurtigere en #2), 
> og være målelig, ganske enkelt forbi den skal bruge færeste load fra 
> memory. 
> 
> OK i små test kommer alt formodeltlig fra 1. level cache.
> 
> Hvis koden afvikles på en maskine med 32bit bus vil fetch af UInt32 fra 
> memory vil i tilfælde #2) kræve 2 load og i tilfælde #1) 1 load.

Det antages så implicit i dit eksempel at adressering i RAM kan ske på 4
bytes adresser.

Når du snakker load, skal man oftere kigge på cachen. IIRC så er de fleste
cacher 16 bytes alignet, så de to structs kan meget vel blive loadet fra 
memory på samme måde (altså hele skidtet ind i cachen, "hver gang" du 
tilgår et enkelt felt.).

Det vil også sige at meget ændrer sig, hvis din struct ikke passer i en 
enkelt cache linie. Nogen gange kan det så bedre betale sig at have mindre 
felter sammen med store, hvis de passer i een linie, og man tilgår dem 
oftere end de andre.

Jeg er enig med dig i at #1 formentlig er hurtigere, men jeg er ikke 
sikker på at du har ret i din begrundelse. :-)

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
Sending Blizzard 100,000 e-mails isn't going to get Starcraft ported to
Linux. Selling 100,000 copies of Quake III is.

            - Scott Draeker, Loki soft, on advocating for Linux games.



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *