简体   繁体   English

如果以相同的方式执行,进程是否应该总是消耗相同数量的内存?

[英]Should a process always consume the same amount of memory if executed in the same way?

Hi folks and thanks for your time in advance. 大家好,谢谢您的宝贵时间。

I'm currently extending our C# test framework to monitor the memory consumed by our application. 我目前正在扩展C#测试框架,以监视应用程序消耗的内存。 The intention being that a bug is potentially raised if the memory consumption significantly jumps on a new build as resources are always tight. 目的是如果由于资源总是紧张而在新的版本上内存消耗大大增加时,可能会引发错误。

I'm using System.Diagnostics.Process.GetProcessByName and then checking the PrivateMemorySize64 value. 我正在使用System.Diagnostics.Process.GetProcessByName,然后检查PrivateMemorySize64值。

During developing the new test, when using the same build of the application for consistency, I've seen it consume differing amounts of memory despite supposedly executing exactly the same code. 在开发新测试的过程中,当使用相同版本的应用程序以保持一致性时,尽管执行了完全相同的代码,但我看到它消耗了不同数量的内存。

So my question is, if once an application has launched, fully loaded and in this case in it's idle state, hence in an identical state from run to run, can I expect the private bytes consumed to be identical from run to run? 所以我的问题是,一旦应用程序启动,完全加载并且在这种情况下处于空闲状态,从而在运行之间处于相同状态,我是否可以期望消耗的私有字节在运行之间是相同的?

I need to clarify that I can expect memory usage to be consistent as any degree of varience starts to reduce the effectiveness of the test as a degree of tolerance would need to be introduced, something I'd like to avoid. 我需要澄清的是,我可以期望内存使用情况保持一致,因为任何程度的差异都会开始降低测试的有效性,因为需要引入一定程度的容忍度,我想避免这种情况。

So... 所以...

1) Should the memory usage be 100% consistent presuming the application is behaving consistenly? 1)假设应用程序表现一致,内存使用率是否应该100%一致? This was my expectation. 这是我的期望。

or 要么

2) Is there is any degree of variance in the private byte usage returned by windows or in the memory it allocates when requested by an app? 2)Windows返回的专用字节使用量或在应用程序请求时分配的内存中是否有任何程度的差异?

Currently, if the answer is memory consumed should be consistent as I was expecteding, the issue lies in our app actually requesting a differing amount of memory. 目前,如果答案是内存消耗应该与我预期的一致,那么问题出在我们的应用程序实际请求的内存量不同。

Many thanks 非常感谢

H H

Almost everything in .NET uses the runtime's garbage collector, and when exactly it runs and how much memory it frees depends on a lot of factors, many of which are out of your hands. .NET中的几乎所有内容都使用运行时的垃圾收集器,确切的运行时间以及释放的内存量取决于许多因素,其中许多是您无法控制的。 For example, when another program needs a lot of memory, and you have a lot of collectable memory at hand, the GC might decide to free it now, whereas when your program is the only one running, the GC heuristics might decide it's more efficient to let collectable memory accumulate a bit longer. 例如,当另一个程序需要大量内存,而您手头有很多可收集的内存时,GC可能会决定立即释放它,而当您的程序是唯一正在运行的程序时,GC启发式方法可能会决定它的效率更高让可收集的内存积累更长的时间。 So, short answer: No, memory usage is not going to be 100% consistent. 因此,简短的回答:不,内存使用率不会保持100%一致。

OTOH, if you have really big differences between runs (say, a few megabytes on one run vs. half a gigabyte on another), you should get suspicious. OTOH,如果两次运行之间确实存在很大差异(例如,一次运行有几兆字节,而另一次运行有几兆字节),则应该变得可疑。

If the program is deterministic (like all embedded programs should be), then yes. 如果程序是确定性的(就像所有嵌入式程序一样),则可以。 In an OS environment you are very unlikely to get the same figures due to memory fragmentation and numerous other factors. 在OS环境中,由于内存碎片和许多其他因素,您不太可能获得相同的数字。

Update: 更新:

Just noted this a C# app, so no, but the numbers should be relatively close (+/- 10% or less). 刚刚注意到这是一个C#应用程序,所以没有,但是数字应该相对接近(+/- 10%或更少)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 内存耗尽总是在同一行 - Running out of memory always on the same line Memory 扫描仪总是返回相同的结果 - Memory scanner always returning the same results 与Java 7相比,运行相同递归代码的相同线程似乎在Java 8中消耗更多堆栈内存 - Same thread running the same recursive code seems to consume more stack memory in Java 8 compared to Java 7 PHP - 为什么按引用传递使用相同数量的内存? - PHP - why does passing by reference use the same amount of memory? cudaMemGetInfo在GTX 690的两个设备上返回相同数量的可用内存 - cudaMemGetInfo returns same amount of free memory on both devices of GTX 690 Apache Child进程消耗大量内存 - Apache Child process consume huge memory 为什么 malloc 使用大量内存返回 NULL 并且总是在同一点? - Why does malloc return NULL with plenty of memory and always at the same point? 两个进程可以共享相同的GPU内存吗? (CUDA) - can two process shared same GPU memory? (CUDA) 如何在Linux中的相同进程下为线程分配堆栈或内存 - How Stack or memory is allocated for threads under the same process in Linux Android-是否有SDK方法可以找出由其pid标识的进程消耗的确切内存量? - Android - Is there an SDK way to find out the exact amount of memory consumed by a process identified by its pid?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM