\$\begingroup\$
\$\endgroup\$
1
Is there a better way than this to copy the values from source to destination when the blocks of memory you want to copy to and from are different sizes? Also considering you have no control over making sure the sizes match to begin with.
while (count--) {
memcpy(dst, src, dst_stride);
src += src_stride;
dst += dst_stride;
}
Heslacher
50.9k5 gold badges83 silver badges177 bronze badges
-
\$\begingroup\$ This seems more of a StackOverflow kind of question. Perhaps migrating it to that site would result in more feedback than in here... \$\endgroup\$glampert– glampert2015年03月06日 17:54:11 +00:00Commented Mar 6, 2015 at 17:54
1 Answer 1
\$\begingroup\$
\$\endgroup\$
If it is possible that the strides match then you can add a if check to just copy it all in one go:
if(src_stride == dst_stride){
memcpy(dst, src, count * dst_stride);
} else {
while (count--) {
memcpy(dst, src, dst_stride);
src += src_stride;
dst += dst_stride;
}
}
answered Mar 6, 2015 at 10:39
lang-c