private void RebuildMemoryMappings()
{
checked
{
var hostBlocks = currentMappings.Where(x => x.Touched).Select(x => x.Segment)
.Select(x => new HostMemoryBlock { Start = (uint)x.StartingOffset, Size = (uint)x.Size, HostPointer = x.Pointer })
.OrderBy(x => x.HostPointer.ToInt64()).ToArray();
for(var i = 0; i < hostBlocks.Length; i++)
{
var j = i;
hostBlocks[i].HostBlockStart = Array.FindIndex(hostBlocks, x => x.HostPointer == hostBlocks[j].HostPointer);
}
var blockBuffer = memoryManager.Allocate(Marshal.SizeOf(typeof(HostMemoryBlock))*hostBlocks.Length);
BlitArray(blockBuffer, hostBlocks.OrderBy(x => x.HostPointer.ToInt64()).Cast<dynamic>().ToArray());
EmulSetHostBlocks(blockBuffer, hostBlocks.Length);
memoryManager.Free(blockBuffer);
this.NoisyLog("Memory mappings rebuilt, there are {0} host blocks now.", hostBlocks.Length);
}
}