As you know, Array.Copy
is faster than manually copying the contents of an array to another, because it does a straight memory copy from one location to another.
But let's say I have a short[]
and a char[]
. You can't do an Array.Copy
between them because they're not of the same type, but the elements in them are the same size, i.e. sizeof(short) == sizeof(char)
. How do I circumvent the type limitation to do a memcpy
from the short[]
to the char[]
, without doing a for loop? I'm talking about something that would be the logical equivalent of reinterpret_cast<>
in C++.
TL;DR: If two arrays have elements of the same size, can you manipulate that to copy elements between them faster? You could always have a for loop, but I'm looking for something more like a straight memcpy
from one array to the other.
Also, I'd like to note one more time that for loops will not be accepted. I am well aware of them, but this is a performance question asking if there is a more efficient way to do this.