This sample illustrates copying the data using fixed pointers. This method of copying is much faster then Buffer.BlockCopy, but requires the /unsafe compiler option. Use it whenever fast copying of buffers is needed. A small code fix is required in this sample to be able to use all options:
The srcIndex and dstIndex parameters are not used in this sample, to enable offset in the source and/or destination buffers add this code within the fixed scope:
//move the pointers to their offset
ps += srcIndex;
pd += dstIndex;
So the code becomes:
...
// The following fixed statement pins the location of the src and dst objects
// in memory so that they will not be moved by garbage collection.
fixed (byte* pSrc=src, pDst = dst)
{
byte* ps = pSrc;
byte* pd = pDst;
//--> ADD THIS: move the pointers to their offset
ps += srcIndex;
pd += dstIndex;
// Loop over the count in blocks of 4 bytes, copying an integer (4 bytes) at a time:
for (int i = 0; i < count / 4; i++)
...
}