gpt4 book ai didi

c# - 确定在抛出 OutOfMemoryException 之前可以使用的可用内存

转载 作者:行者123 更新时间:2023-11-30 12:47:57 25 4
gpt4 key购买 nike

我的应用程序的 OutOfMemoryException 在系统本身内存不足之前抛出,如下所述:
MSDN Blogs - Out of memory? Easy ways to increase the memory available to your program.

When you run your C# application, you might get an OutOfMemoryException thrown, even if your machine has lots of memory. [...] That 4 Gigs is divided into half: the user application gets the lower half and the OS gets the upper. (This boundary can be changed: see below).

根据要求,我需要可视化有多少内存可用于我的应用程序和当前使用情况。可以使用 Process.GetCurrentProcess(); 和其他方法检索当前使用情况,但如何确定我的应用程序在运行时可用的内存?我就是想不通。

最佳答案

您可以使用 MemoryFailPoint大配置前要检查。这并不是您所要求的,但如果您的失败发生在特定的已知大型分配点,这至少允许您在分配失败发生时干净地处理它。

关于c# - 确定在抛出 OutOfMemoryException 之前可以使用的可用内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15305976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com