🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.image.processing
Article #342

Re: image processing loops: a c programming question

#342
From: "Adrian F Clark"
Date: Thu, 13 Aug 1992 11:05
37 lines
1720 bytes
In article <1992Aug10.221247.8016@cfa.harvard.edu> alberto@cfa.harvard.edu (Alberto Accomazzi) writes:

> A far as making the loop tight and fast, if you are only accessing your data
> in a sequential way, the best thing to do is increment the pointer as in:
> 
> function (DATATYPE *data, int xsize, int ysize)
> {
>   int x, y;
>   DATATYPE *dp;
> 
>   dp = data;
>   for (y = 0; y < ysize; y++)
>     for (x = 0; x < xsize; x++, dp++)
>       *dp = ...
> }
> 
> Inner loops can be written in a similar fashion.  As far as I know, this
> will be as fast as you can get.

Actually, you can get just a smidgin faster on most machines:

  dp = data;
  for (y = 0; y < ysize; y++)
    for (x = 0; x < xsize; x++)
      *dp++ = ...
}

but this is probably even less readable than the other examples
posted.


--
 Dr Adrian F. Clark                                   JANET: alien@uk.ac.essex
 INTERNET: alien%uk.ac.essex@nsfnet-relay.ac.uk          FAX: (+44) 206-872900
 BITNET: alien%uk.ac.essex@ac.uk              PHONE: (+44) 206-872432 (direct)
 Dept ESE, University of Essex, Wivenhoe Park, Colchester, Essex, C04 3SQ, UK.
Technical Details
Message-ID: <ALIEN.92Aug13120523@vulcan.essex.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!sersun1!alien
References: <SLEHAR.92Aug7111245@kendall.bu.edu> <1992Aug10.221247.8016@cfa.harvard.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!sersun1!alien
From: alien@essex.ac.uk ("Adrian F Clark")
Newsgroups: sci.image.processing
Subject: Re: image processing loops: a c programming question
Message-ID: <ALIEN.92Aug13120523@vulcan.essex.ac.uk>
Date: 13 Aug 92 11:05:23 GMT
References: <SLEHAR.92Aug7111245@kendall.bu.edu> <1992Aug10.221247.8016@cfa.harvard.edu>
Sender: news@sersun1.essex.ac.uk
Distribution: sci.image.processing
Organization: University of Essex, UK
Lines: 37
In-reply-to: alberto@cfa.harvard.edu's message of 10 Aug 92 22:12:47 GMT