🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.image.processing
Article #357

Re: image processing loops: a c programming question

#357
From: Ellis Workman, 1-157 Med Sci, 4-...
Date: Thu, 13 Aug 1992 19:34
72 lines
2680 bytes
In article 713717257@isy, stefang@isy.liu.se (Stefan Gustavson) writes:
>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++= ...)


			???????

		DO YOU REALLY WANT TO DO THE 
		
			xsize*ysize*sizeof(int)
			
			(compute byte count)
		
		ON EVERY ITERATION OF THE LOOP??????


				ISHHHH ...

how about
			for(i=xsize*ysize, dp = data;i;i--)
				*dp++ = ...;


-------------------------------------------------------
Ellis Workman                   Internet:  elw@mayo.edu
Biomedical Imaging Resource
Mayo Foundation                 Talk:    (507) 284-4435                  
Rochester, MN 55905             FAX:     (507)-284-1632
-------------------------------------------------------
Technical Details
Message-ID: <1992Aug13.193434.660@bmw.mayo.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!sgigate!odin!mips!sdd.hp.com!uakari.primate.wisc.edu!zazen!doug.cae.wisc.edu!umn.edu!bru!jaguar!elw
References: <stefang.713717257@isy>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!sgigate!odin!mips!sdd.hp.com!uakari.primate.wisc.edu!zazen!doug.cae.wisc.edu!umn.edu!bru!jaguar!elw
From: elw@jaguar.sky2 (Ellis Workman, 1-157 Med Sci, 4-4435)
Newsgroups: sci.image.processing
Subject: Re: image processing loops: a c programming question
Message-ID: <1992Aug13.193434.660@bmw.mayo.edu>
Date: 13 Aug 92 19:34:34 GMT
References: <stefang.713717257@isy>
Sender: newsman@bmw.mayo.edu (/home/bmw/usenet)
Reply-To: elw@jaguar.sky2
Organization: Sun Microsystems
Lines: 72