www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/15/18:15:50

Xref: news2.mv.net comp.os.msdos.djgpp:5009
From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Speed optimization: memcpy() or for loop ??
Date: Fri, 14 Jun 1996 23:26:05 -0700
Organization: Alcyone Systems
Lines: 31
Message-ID: <31C2577D.22FD99BD@alcyone.com>
References: <4pmlrp$p7u AT crc-news DOT doc DOT ca>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Richard Young wrote:

> A question for the optimization experts:
> 
> For moving data, is it faster to use
> 
> a) memcpy(x,y,n*sizeof(x[0]))
> 
> or
> 
> b) for (i = 0; i < n; i++) x[i] = y[i];
> 
> or are they basically the same speed.

Use the standard library function.

The whole idea behind having such a function is that it is supposed to be a
good implementation of the operation you're interested in.  And, furthermore,
it knows which platform it's running under, so to speak, and so it can do the
right thing.

> With C++ is it better code practice to use b) over a)?

Same thing.

-- 
Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max AT alcyone DOT com
San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
"Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_

- Raw text -


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