Place the R drive (RamDisk using Imdisk) and the C drive (SSD) in the memory mapping file, respectively.
However, there is a large difference in disk read and write speed, but there is little difference in memorymappedfile performance.
Why is the performance of a memory mappedfile not proportional to the performance of the disk?
this code used performance test C and R driver. args[0] is file path in C or R driver.
The stopwatch count is the same no matter which drive is selected.
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
int i = Int32.Parse("100");
Console.Write("count " + i + ", ");
string path = "C:\\Users\\TBB_miniPC\\Desktop\\dummy\\ain.jpg";
FileStream file = new FileStream(path, FileMode.Open);
BinaryReader reader = new BinaryReader(file);
byte[] buffer = new byte[file.Length];
reader.Read(buffer, 0, buffer.Length);
reader.Close();
file.Close();
long offset = 0x00000000; // 0 megabytes
long length = 0x10000000; // 256 megabytes
Stopwatch sw = new Stopwatch();
sw.Start();
using (var mmf = MemoryMappedFile.CreateFromFile(args[0], FileMode.Open, "die", buffer.Length+1) )
{
using (var accessor = mmf.CreateViewAccessor(0, buffer.Length))
{
while(i > 0)
{
accessor.WriteArray<byte>(0, buffer, 0, buffer.Length);
i -= 1;
}
sw.Stop();
Console.WriteLine("time" + sw.ElapsedMilliseconds);
}
}
}
}