www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/03/06:13:39

Message-ID: <32F662F9.1F3B@post.comstar.ru>
Date: Mon, 03 Feb 1997 14:13:13 -0800
From: Dim Zegebart <zager AT post DOT comstar DOT ru>
Reply-To: zager AT post DOT comstar DOT ru
Organization: zager AT post DOT comstar DOT ru
MIME-Version: 1.0
To: DJGPP Mail List <djgpp AT delorie DOT com>
Subject: Using Pointers ?

Damn again !
Sorry for previous msg it's incomleet (try press Ctrl-K-H :) in Netscape
Mail and your msg sending :(  )

Hi,
I have small question about speed optimization.
Here are free functions making the same things but different ways:

//FOO1
int foo1(TMyType *ptr)
{
 //TMyType has fields fld1 and fld2 both int
 int i;
 for (i=0;i<100000;i++) 
  { ptr->fld1++; //here may be any expression. ++ just for example
    ptr->fld2--;
  }
 return(1);
}

//FOO2
int foo2(TMyType *ptr)
{
 //TMyType has fields fld1 and fld2 both int
 int i,*fld1=&ptr->fld1,*fld2=&ptr->fld2;
 for (i=0;i<100000;i++) 
  { *fld1++; //here may be any expression. ++ just for example
    *fld2--;
  }
 return(1);
}

//FOO3
int foo3(TMyType *ptr)
{
 //TMyType has fields fld1 and fld2 both int
 int i,fld1=ptr->fld1,fld2=&ptr->fld2;
 for (i=0;i<100000;i++) 
  { fld1++; //here may be any expression. ++ just for example
    fld2--;
  }
 ptr->fld1=fld1;
 ptr->fld2=fld2
 return(1);
}

-- 
Regards,
Dim Zegebart,
Moscow Russia.

- Raw text -


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