本文介绍了极限内存条件测试:如何使RAM饱和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一小段程序来启动线程,以线性方式消耗可用的RAM内存,直到达到一定级别,然后停止(理想情况下,暂停直到释放足够"的内存,然后继续创建线程),依此类推.)

I would like to write a small piece of program that launches threads, consumes available RAM memory in a linear fashion, until a certain level, and stops (ideally, pauses until "enough" memory is freed and continues creating threads after that, and so on.)

我尝试了以下操作,但是 list.Add(new byte [])需要连续的RAM空间并丢弃 OutOfMemoryException ,这不是我要尝试的操作模拟.

I tried the following, but the list.Add(new byte[]) requires contiguous RAM space and drops an OutOfMemoryException, which is NOT what I am trying to simulate.


我有一个需要消耗大量内存的多线程应用程序.我只想在实验室条件"中隔离/重现这种情况以解决该问题,即编写一个自适应的内存监视/线程限制器草案.我正在使用x64 OS和x64平台.明确地说:由于程序的原因,我想看到的结果是任务管理器内存监视器直接上升.

EDIT :
I have a multi-threaded memory-hungry application that eats up a whole bunch of RAM GB's. All I want is to isolate/reproduce that situation in "Lab conditions" to tackle it, i.e write an adaptive mem-monitoring / thread-limiter draft. I am using x64 OS an x64 Platform.To make it clear : The result I want to see is the Task Manager Memory Monitor going up straight due to the program.

    static void Main(string[] args)
    {
        ComputerInfo ci = new ComputerInfo();
        D("TOTAL PHYSICAL MEMORY : " + Math.Round(ci.TotalPhysicalMemory / Math.Pow(10,9),3) +" GB");

        //########### Fill Memory ###############
        var list = new List<byte[]>();

        Thread FillMem= new Thread(delegate()
        {
            while (Process.GetCurrentProcess().PrivateMemorySize64 < MAX_MEM_LEVEL)
            {
                list.Add(new byte[1024 * 10000]); //<- I Need to change this
                Thread.Sleep(100);
            }
        });

        FillMem.Start();

        //########### Show used Memory ###############
        Thread MonitorMem = new Thread(delegate()
        {
            while (true)
            {
                D("PROCESS MEMORY : " + Math.Round(Process.GetCurrentProcess().PrivateMemorySize64 / Math.Pow(10, 6), 3) + " MB");
                Thread.Sleep(1000);
            }
        });

        MonitorMem.Start();

        Console.Read();
    }

推荐答案

问题仍然很令人困惑;我不清楚您在这里打算做什么以及为什么这么做.

The question is still quite confusing; it is not clear to me what you are trying to do here and why.

如果您真的想消耗物理内存-也就是说,告诉操作系统否,请不要真正使用计算机中安装的物理RAM芯片的这一部分而不是我说的话-那么我可能会使用名称恰当的通过非托管代码分配UserPhysicalPages 函数.

If you genuinely want to be consuming physical memory -- that is, telling the operating system no, really do not use this portion of the physical RAM chip that is installed in the machine for anything other than what I say -- then I would probably use the aptly-named AllocateUserPhysicalPages function from unmanaged code.

这将减少可用于其他用途的物理内存量,从而迫使更多的虚拟内存页面进入页面文件.

That will then reduce the amount of physical memory that is available for other uses, forcing more virtual memory pages to go out to the page file.

除了使计算机上运行的所有程序变慢很多之外,我不确定您打算通过该方法完成什么.你能澄清一下吗?

Other than making all the programs running on your machine a whole lot slower, I'm not sure what you intend to accomplish by this. Can you clarify?

这篇关于极限内存条件测试:如何使RAM饱和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 16:32