Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: memcpy vs. memmove (was: Re: Explanation, please!)
Message-ID: <1988Sep13.234434.5410@utzoo.uucp>
Organization: U of Toronto Zoology
References: <8389@smoke.ARPA> <7039@bloom-beacon.MIT.EDU>
Date: Tue, 13 Sep 88 23:44:34 GMT

In article <7039@bloom-beacon.MIT.EDU> scs@adam.pika.mit.edu (Steve Summit) writes:
>I'll probably be disgusted by the answer, but can someone explain
>why two functions are needed instead of one?  Why not just add
>the guarantee to memcpy? ...

The key observation is that in many cases the programmer knows that the
source and destination do not overlap, and it is difficult for the compiler
to figure this out except by checking it at run time.  This is particularly
significant if the compiler is doing inlining for efficiency and relatively
small amounts of data are being moved -- in such a case, the overlap check
may significantly hurt performance.  Since the older definitions of memcpy
explicitly said "if the operands overlap, no guarantees", it seemed sound
to make memcpy the fast-but-dangerous case and add a new function for the
slow-but-safe case.
-- 
NASA is into artificial        |     Henry Spencer at U of Toronto Zoology
stupidity.  - Jerry Pournelle  | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
