🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1984

Re: Do we need a standard isPointer() function?

#1984
From: J. Kanze
Date: Mon, 18 Sep 1995 09:23
35 lines
2080 bytes
Pablo Halpern (phalpern@truffle.ultranet.com) wrote:
|> I am trying to optimize a template for use with built-in types and
|> pointers. I have a function that moves objects within or between arrays.
|> The first cut is simply:

|>   template <class type>
|>   void List<type>::move_elems(type *dest, const type *src, int numelems)
|>   {
|>     // Copy elements one at a time using type's assignment operator
|>     while (numelems-- > 0)
|>       *dest++ = *src++;
|>   }

|> This will work for any type with a canonical operator=(). However, this
|> is not efficient for built-in types and pointers, which are better
|> copied with the following expression:

|>   memmove(dest, src, sizeof(type) * numelems);

Is this really true?  I was under the impression that on most machines
where it made a significant difference (CISC architectures), the
compilers did this optimization for you.  (Microsoft once had a full
page ad in Byte claiming they did it in their C compiler; as this was a
fairly long time ago, I would imagine that most compilers are doing it
today.  Of course, on a RISC, it probably won't make a significant
difference.)
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle--
                             --Beratung in industrieller Datenverarbeitung
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <43j84e$61g@gabi.gabi-soft.fr>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <439kkn$n81@caesar.ultra.net>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 18 Sep 95 09:23:47 GMT
Approved: fjh@cs.mu.oz.au
From: kanze@gabi-soft.fr (J. Kanze)
Newsgroups: comp.std.c++
Subject: Re: Do we need a standard isPointer() function?
X-Original-Date: 18 Sep 1995 09:46:22 +0200
Organization: GABI Software, Sarl.
Message-ID: <43j84e$61g@gabi.gabi-soft.fr>
References: <439kkn$n81@caesar.ultra.net>
X-Newsreader: TIN [version 1.2 PL2]