相关到我的previous问题: $p$pventing内存问题处理大量文字时
Related to my previous question: Preventing Memory issues when handling large amounts of text
有没有办法来确定多少内存空间,我的计划是占领?我最终处理大量的文本文件,通常存储在处理内存中的对象。有次,其中会有太多的信息,我会耗尽内存。我对避免内存分配问题的解决办法,但我只希望在必要的时候使用它,以避免分页,这最终会降低我的表现时,它不是必需的。有没有办法找出我多少内存占用,使我只能页我的信息在必要的时候?
Is there a way to determine how much memory space my program is occupying? I end up processing a large amount of text file and usually store the processed objects in memory. There are times where there will be too much information, and I will run out of memory. I have a solution for avoiding the memory allocation problem, but I only want to use it when necessary, to avoid paging, which will ultimately decrease my performance when it's not necessary. Is there a way to figure out how much memory I am occupying, so that I can page my information only when necessary?
注意:我要寻找我的程序可以利用必要的时候开始寻呼解决方案
NOTE: I am looking for a solution that my program can utilize to begin paging when necessary.
您可以尝试的 GC.GetTotalMemory
:
You can try GC.GetTotalMemory
:
检索的字节数 目前认为待分配。一个 参数指示是否该 方法可以等待很短的时间间隔 在返回之前,以允许系统 收集垃圾并最终确定 对象。
Retrieves the number of bytes currently thought to be allocated. A parameter indicates whether this method can wait a short interval before returning, to allow the system to collect garbage and finalize objects.
要注意的重要一点是这部分:获取的字节数的目前认为分配的。这意味着,此方法可能不是100%准确 - 只要你知道这会在,你应该能够得到您的虚拟内存使用的一个粗略的想法在你的应用程序执行给定的点
The important thing to note is this part: "Retrieves the number of bytes currently thought to be allocated". This means that this method may not be 100% accurate - as long as you know this going in, you should be able to get a rough idea of your virtual memory utilization at a given point in your application execution.
编辑:现在让我来提供不同的解决方案,可能会更有成效:使用的 性能监视器
和的 CLR性能计数器的。
Let me now offer a different solution that will probably be more productive: use perfmon
and the CLR performance counters.