Game Development Reference
In-Depth Information
}
}
unsafeTime = Environment.TickCount - unsafeTime;
uncheckedTime = Environment.TickCount;
unsafe
{
unchecked
{
fixed (byte* dataPtr = data)
{
byte* dataByte = dataPtr;
for (int index = 0; index < data.Length; index++)
{
*dataByte++ = (byte)index;
// Can also do: *(dataByte + index) = (byte)index;
}
}
}
}
uncheckedTime = Environment.TickCount - uncheckedTime;
Console.WriteLine(“Unsafe Elapsed Time: “ +
unsafeTime.ToString() + “ ticks”);
Console.WriteLine(“Unchecked Elapsed Time: “ +
uncheckedTime.ToString() + “ ticks”);
}
Example: Data Block Copying
The following example copies the data from a source array into a destination array,
serving as a replacement for Array.Copy() .
static void DataBlockCopy()
{
int dataLength = 100000000;
byte[] sourceData = new byte[dataLength];
Search Nedrilad ::




Custom Search