How to control memory allocation from code

I have a Windows service that ultimately throws an Out of Memory exception. It is written in C # and runs on Windows 7.

Yes . I read existing questions about this on Stack Overflow, as well as elsewhere on the Internet. If true, I found an excellent article by Eric Lippert entitled "From Memory", without referring to physical memory, where he gives a very clear explanation of this condition.

http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx?PageIndex=1#comments

In this article, he refers to "out of memory" with the statement: "This is currently the wrong name. It really should be the error" inability to find a sufficiently adjacent address space ", you have a lot of memory because the memory is equal to disk space."

He also states:

An “out of memory” error almost never occurs because they do not have enough free space; as we saw, storage is disk space, and disks are huge these days. Rather, an out-of-memory error occurs because the process cannot find a large enough portion of continuous unused pages in its virtual address space to perform the requested mapping.

PerfMon, Commit, Working Set Private, . , , - , .

, - #, , , ? , .

+4
1

#, , Windows .

private float GetActuratePrivateWorkingSet(Process currentProcess)
    {
        // get the physical mem usage for this process
        var pc = new PerformanceCounter("Process", "Working Set - Private", currentProcess.ProcessName, true);
        pc.NextValue();
        Thread.Sleep(1000);
        var privateWorkingSet = pc.NextValue()/ 1024/1024;
        return privateWorkingSet;
    }

, , .  - , . ... # .

#... Windows, , .

Windows -.... ... , -, .

, Windows, .

PS. : Ant . , , , .

+1

Source: https://habr.com/ru/post/1608016/


All Articles