如何使耗尽内存在.NET过程中无需耗尽所有系统内存过程中、内存、存在、系统

2023-09-04 02:13:33 作者:”丢一地的真心没人珍惜

这个问题很简单我有一个过程,但这对一些XML文件的ETL。我们开始变得非常大的XML文件,我开始OutOfMemoryExceptions。

The problem is simple I have a process, that does ETL on some xml files. We started getting really large xml files and I started getting OutOfMemoryExceptions.

修复过程比较简单。但是,我想作一个单元测试我的NUnit的套件,以确保进程将继续能够处理真正大型文件。然而,实际上运行内存我的开发工作站上减慢我的机器,并且非常耗时。存储在版本控制一个巨大的测试文件也是一个坏主意。如果我能人为地限制一个进程,线程或应用程序域只使用RAM的固定数额,可以说128兆,我可以做一个更小的单元测试,不会把我的工作站,它的膝盖。

Fixing the process is relatively simple. However, I'd like to make a unit test for my NUnit suite to make sure the process will continue to be able to handle really large files. However, actually running out of memory on my development workstation slows down my machine, and is time consuming. Storing a humongous test file in version control is also a bad idea. If I could artificially limit a process, thread or appdomain to only use a fixed amount of ram, lets say 128 megs, I could make a smaller unit test that would not bring my workstation, to its knees.

有什么建议?是他们的一些非托管API我可以P / Invoke?

Any suggestions? Is their some unmanaged API I can P/Invoke?

推荐答案

你能不能用嘲弄的框架的内存分配,并把它扔 OutOfMemoryException异常为一体测试?

Can't you use a mocking framework for the memory allocation and have it throw OutOfMemoryException as one of the tests?

说了这么多,虽然,如果你真的已经耗尽内存没有太多的应用程序可以安全地做,但如果你至少可以优雅地失败,你的用户会很感激。

Having said that though, if you really have run out of memory there's not much your application can safely do, but if you can at least fail gracefully your users will be grateful.

一个例子: 我曾在一个previous的工作,我们是在实时显示工厂的3D模型的情况。该模型变得如此之大,以至于当我们试图加载纹理我们会走出内存故障。我们成功地保持应用程序活着,并通过确保在code应付空指针,即使的code,其余认为应该有纹理​​信息有渲染。

An example: I had a case in a previous job where we were displaying 3D models of factories in real-time. The models grew so large that when we tried to load textures we'd get out of memory failures. We managed to keep the application alive and rendering by making sure that the code coped with null pointers even though the rest of the code thought that there should be texture information there.

 
精彩推荐
图片推荐