<Pe*******@gmai l.com> wrote
Suppose I have a void pointer pointing to a chunk of memory, I want to
copy the contents to another chunk of memory. Of course I can convert
void pointer to char pointer and use a for loop to copy each char, but
I fill it is slow. Is there any way I can copy the whole chunk at one
shot.
Normally when you want to do this, the array will be an array of integers or
whatever.
So by writing the function
copyint(int *dest, int *source, int N)
you can copy each int in a single instruction, which will usually be faster
than copying over one byte at a time.
memcpy() will often do this internally by looking for arguments which are a
whole number of integers and suitably aligned. You can do this yourself, but
obviously as soon as you start looking at pointer alignments directly you
have lost portability.
Also, some computers come with a DMA engine, which will copy large chunks of
memory asynchronously. You can't write a C interface to such a device in
ANSI C, of course, for often some C-callable function will be provided to
use it.