C # memory file does not take up physical memory

I am trying to cache a large amount of data in physical memory and share it for other processes in the local environment. So I came up with MMF and read the Microsoft MMF document, saw some examples, and started setting up similar code.

MemoryMappedFile MMF = MemoryMappedFile.CreateNew("Features", MaxSize); . . . using (MemoryMappedViewStream stream = MMF.CreateViewStream()) { BinaryWriter write = new BinaryWriter(stream); . . . // Fetched the data from database and store it into Rowdata variable. while (Rowdata.Read()) { byte[] data = Rowdata.GetFieldValue<byte[]>(0); write.Write(data); } } 

It does not store data in memory

IVSSharedMemory is what I am working on, but the amount of memory should be much higher than that.

enter image description here

Is there something I forgot to do when I created a memory mapping file? please tell me if there is any. I googled it right after I noticed this unexpected behavior, and some said it was virtual memory. But I cannot help but think that this is not true, because the document explains this in the section below.

Inconsistent display files

The CreateNew and CreateOrOpen methods create a memory-mapped file that does not map to an existing file on disk.

Thanks in advance. Just confirmed that this is what the MMF is for.

UPDATE


It seems to be really virtual memory. As Mike Z commented, I checked the memories that my application stored in the VMMAP tool, and as a result I got exactly what I wanted.

enter image description here

But look at this, the amount of allocated memory has changed. This happens when my application downloads all the data completely. I can assume that the previous size just points to the MaxSize that I assigned when creating the MMF.

enter image description here

Did it take up physical disk space or something?

I read a lot about MemoryMappedFile and tried to see what was underground. But I still do not understand why this is happening. Seriously, where is the data? where can i check this?

+10
c # shared-memory mmf
source share
1 answer

A memory mapping file is functionality provided by the core of most modern operating systems. Its purpose is not to load the file into real physical memory, but to use the virtual memory mapping functionality to provide access to the contents of the file as if it were a memory block.

To be more precise, modern operating systems use a pagination mechanism that uses a computer’s MMU computer to map the virtual address space to physical memory or a swap file on disk. So virtual memory is implemented. The idea is that the MMU converts memory access from the CPU to RAM using a display supported by the kernel, or if the page is missing (either it was transferred to disk or not displayed at all), and then it creates a hardware interrupt that will cause the kernel to fix cache error. In the case of a file with a display in memory, this resolution takes care of loading the missing page into the main memory and transparently resumes the program.

0
source share

All Articles