🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.image.processing
Article #353

Re: image processing loops: a c programming question

#353
From: Stefan Gustavson
Date: Thu, 13 Aug 1992 14:47
49 lines
2177 bytes
alien@essex.ac.uk ("Adrian F Clark") writes:


>In article <1992Aug10.221247.8016@cfa.harvard.edu> alberto@cfa.harvard.edu (Alberto Accomazzi) writes:

>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.

You really don't need a separate x counter varaiable. Use the
pointer itself for the inner loop:

  dp = data;
  for (y = 0; y < ysize; y++)
   {
     rowend = (y+1)*xsize*sizeof(int); /* or whatever size your data is */
     for ( ; (int)dp < rowend; )       /* note the obscure empty statements */
       *dp++ = ...
   }

This saves one increment instruction. It makes a difference.
Yes, I have written a program like this. No, I wouldn't like to
try to read somebody else's program written like this.

And now for the *really* compact stuff...

For greater obscurity, you could use the pointer for the outer loop, too,
and move some initialization inside the for(;;) construct, and remove the
silly type casts that weenie compilers try to make you put in there:

  for(dp=data; dp<xsize*ysize*sizeof(int);)
    {
      for(rowend = dp+xsize*sizeof(int); dp<rowend; )
        *dp++ = ...
    }

Or if you don't care which row you are on, you could just write:

  for(dp=data; dp<xsize*ysize*sizeof(int); *dp++= ...)

Or if you like to... Hey! Let go of me! I'm writing an article here!
No, I don't need a vacation. And I won't let that man in the white robe
get anywhere near me with that needl
Technical Details
Message-ID: <stefang.713717257@isy>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!liuida!isy!isy!stefang
References: <SLEHAR.92Aug7111245@kendall.bu.edu> <1992Aug10.221247.8016@cfa.harvard.edu> <ALIEN.92Aug13120523@vulcan.essex.ac.uk>

Show Full Headers
Complete Article Headers
Newsgroups: sci.image.processing
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!liuida!isy!isy!stefang
From: stefang@isy.liu.se (Stefan Gustavson)
Subject: Re: image processing loops: a c programming question
Message-ID: <stefang.713717257@isy>
Sender: news@isy.liu.se (Lord of the News)
Organization: Dept of EE, University of Linkoping
References: <SLEHAR.92Aug7111245@kendall.bu.edu> <1992Aug10.221247.8016@cfa.harvard.edu> <ALIEN.92Aug13120523@vulcan.essex.ac.uk>
Distribution: sci.image.processing
Date: 13 Aug 92 14:47:37 GMT
Lines: 49