CONTENTS | INDEX | PREV | NEXT
memcpy
movmem
bcopy
memmove
NAME
memcpy - copy memory ANSI, does not work with overlapped memory buffers
memmove - copy memory ANSI, works with overlapped memory buffers
movmem - copy memory works with overlapped memory buffers
bcopy - copy memory UNIX, works with overlapped memory buffers
SYNOPSIS
void *ptr = memcpy(d, s, bytes);
void *ptr = memmove(d, s, bytes);
void *ptr = movmem(s, d, bytes);
void *ptr = bcopy(s, d, bytes);
void *d;
void *s;
size_t bytes;
FUNCTION
these functions copy memory from one region to another. Unlike
string routines these functions do not stop the copy when a nul
is encountered.
NOTE
DICE's memory move optimizes the copy using movem when possible,
yielding very fast memory copies for large buffers.
WARNING
BE CAREFUL about argument ordering. Some calls take the source
buffer first and other calls take the destination buffer first.
The ANSI committee really screwed up its standard, going for a
destination, source ordering rather than the more logical
source, destination ordering. Thus, many programmers will use
the non-standard movmem() call instead of the ANSI memmove() call.
The ANSI function 'memcpy' as defined by the ANSI standard cannot
handle overlapped memory areas. The Amiga implementation can but
you should remember this if you intend to port your code.
The UNIX bcopy call exists for compatibility purposes and should
not be used with new programs.
EXAMPLE
/*
* This example copies the entire buffer, not just the part
* containing the string. Normally one just uses string routines.
*/
#include <string.h>
#include <assert.h>
main()
{
char s[16];
char d[16];
void *p;
strcpy(s, "This is a test");
p = movmem(s, d, sizeof(s));
assert(p == d);
puts(d);
strcpy(s, "FuBarBletch");
p = bcopy(s, d, sizeof(s));
assert(p == d);
puts(d);
strcpy(s, "EchoBeko");
p = memcpy(d, s, sizeof(s));
assert(p == d);
puts(d);
strcpy(s, "GakFuBar");
p = memmove(d, s, sizeof(s));
assert(p == d);
puts(d);
return(0);
}
INPUTS
void *s; source buffer
void *d; destination buffer
RESULTS
void *ptr; pointer to the destination buffer (d)