Regarding doing this in Java:
Your loop
for(int i = 0 ; i < SourceDataSize ; i ++ ) {
Destination[i] = SourceData[i + 0x100];
}
will always start copying data from 0x100
elements into SourceData; this may not be desired behavior. (For instance, when i=0
, Destination[0] = SourceData[0 + 0x100];
and so forth.) This would be what you wanted if you never wanted to copy SourceData[0]..SourceData[0xFF]
, but note that hard-coding this prevents it from being a drop-in replacement for memcpy.
The reason the intSize
value is specified in the original code is likely because the first intSize
elements are not part of the 'actual' data, and those bytes are used for bookkeeping somehow (like a record of what the total size of the buffer is). memcpy
itself doesn't 'see' the offset; it only knows the pointer it's starting with. SourceData + intSize
creates a pointer that points intSize
bytes past SourceData
.
But, more importantly, what you are doing is likely to be extremely slow. memcpy
is a very heavily optimized function that maps to carefully tuned assembly on most architectures, and replacing it with a simple loop-per-byte iteration will dramatically impact the performance characteristics of the code. While what you are doing is appropriate if you are trying to understand how memcpy and pointers work, note that if you are attempting to port existing code to Java for actual use you will likely want to use a morally equivalent Java function like java.util.Arrays.copyOf
.