memcpy speed

Sep 5, 2010 at 10:46am
Hi.
I wonder what is faster - copying a long memory or rather more pieces of short data.
Imagine two long arrays of chars (hundreds thousand), which should contain the same data.
Now I change only some blocks (lets say tens blocks of 100 chars) spread in first array.
Is it faster to copy the whole array using memcpy(array2, array1, array1Length); or in a for cycle copy just the blocks? Positions of the blocks are easy to compute.

The application is designed for ARM and PowerPC architectures. I suppose the situation may differ from PC. Does anyone have such experience that (s)he could advice me?

Thanks in advance,
yman
Sep 5, 2010 at 2:32pm
Copying only the updated sections will be slightly faster than copying the entire array. If it's easy to determine which sections need copying, go ahead, but copying a few hundred kilobytes takes almost no time, so you probably won't even be able to measure the difference.
Sep 7, 2010 at 10:23am
copying a long memory or rather more pieces of short data.


If it is meant division the long one into pieces then yes.
Because to copy the whole may take one step only unlike
its pieces that are needed to be counted in advance followed
by a repeatetion of the copying.
This seemingly transparent operations are going somewhere
in an architecture despite of all the exposure.
Sep 8, 2010 at 2:31pm
I will say you should copy pieces of data rather than long memory and use "LOOP UNROLLING" technique with that. It will make copying more faster.
If this part of your code is going to be used extensively in your program then you should follow the above method then you will experience difference.
Sep 8, 2010 at 2:40pm
Copying a large chunk of contiguous memory as a single copy is at least as fast as copying a large chunk of contiguous
memory as multiple smaller copies of pieces, and quite probably faster.

The speed of copying a large chunk of contiguous memory vs. copying only the modified portions does not have a
generalized answer, as helios said, because it depends on how fast finding the modified portions is and what
percentage of the data is modified compared to just copying everything.
Topic archived. No new replies allowed.