는 : 랜덤 액세스가있는 경우 40GB의 파일은, 매우 이상한 행동이 :메모리 매핑 된 파일 및 메모리 소비
static void Test()
{
string fileName = @"d:\map";
long length = new FileInfo(fileName).Length;
using (var file = MemoryMappedFile.CreateFromFile(fileName, FileMode.Open, "mapFile", length, MemoryMappedFileAccess.ReadWrite))
{
byte* bytePtr = (byte*)0;
var view = file.CreateViewAccessor(0, length, MemoryMappedFileAccess.ReadWrite);
view.SafeMemoryMappedViewHandle.AcquirePointer(ref bytePtr);
long count = (long)(length/sizeof(int));
long sum = 0;
long step = count/2000;
int* ptr = (int*)&bytePtr[0];
long currentCount = 0 ;
Parallel.For(0, count, new ParallelOptions { MaxDegreeOfParallelism = 8 }, (i) =>
{
Interlocked.Add(ref sum, ptr[i]);
Interlocked.Increment(ref currentCount) ;
if (currentCount % step == 0)
Console.Write("\r{0:0.00}%", (100 * currentCount/(float)count));
});
Console.WriteLine(sum);
view.Dispose();
}
}
"\ 맵 d는"점을 감안 포인터 "ptr"을 통해.
시스템의 실제 메모리가 완전히 사용되며 모든 작업이 느려지므로이 프로세스를 완료하는 데 2 시간 이상이 걸립니다.
순차적 (및 단일 스레드) 액세스 권한이있는 경우 사용 된 실제 메모리는 1GB가 아니며 프로세스는 약 8 분이 걸립니다.
내 질문은 : 메모리 매핑 된 파일을 사용할 때 "실제"메모리가 사용됩니까? 점령되는 가상 주소 공간뿐만 아니라?
메모리 매핑 된 파일을 사용할 때 실제 메모리 사용량을 이해하려고합니다.