Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Regarding doing this in Java:</p> <p>Your loop</p> <pre><code>for(int i = 0 ; i &lt; SourceDataSize ; i ++ ) { Destination[i] = SourceData[i + 0x100]; } </code></pre> <p>will always start copying data from <code>0x100</code> elements into SourceData; this may not be desired behavior. (For instance, when <code>i=0</code>, <code>Destination[0] = SourceData[0 + 0x100];</code> and so forth.) This would be what you wanted if you never wanted to copy <code>SourceData[0]..SourceData[0xFF]</code>, but note that hard-coding this prevents it from being a drop-in replacement for memcpy.</p> <p>The reason the <code>intSize</code> value is specified in the original code is likely because the first <code>intSize</code> 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). <code>memcpy</code> itself doesn't 'see' the offset; it only knows the pointer it's starting with. <code>SourceData + intSize</code> creates a pointer that points <code>intSize</code> bytes past <code>SourceData</code>.</p> <p>But, <strong>more importantly</strong>, what you are doing is likely to be <strong>extremely slow</strong>. <code>memcpy</code> is a <em>very</em> 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 <strong>appropriate if you are trying to understand how memcpy and pointers work</strong>, 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 <code>java.util.Arrays.copyOf</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload