创建消耗内存的应用程序

发布于 01-07 16:00 字数 157 浏览 2 评论 0原文

我想编写一个在服务器上消耗大量内存的应用程序,以便能够显示与服务器上的内存压力相关的问题。我对 C# 相当了解,但我很好奇导致应用程序以可控方式消耗过多内存的最有效方法是什么。例如,我希望能够传递一个表示消耗 x MB 内存的参数,并让它消耗接近该值的位置。任何关于我如何做到这一点的想法将不胜感激。

I want to write an application that consumes a lot of memory on a server to be able to show problems associated with memory pressure on a server. I know C# fairly well, but I am curious what the most efficient method of causing an application to consume excessive amounts of memory in a controllable manner. For example, I'd like to be able to pass a parameter that says to consume x MB of memory and have it consume somewhere close to that value. Any thoughts on how I might do this would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

知足的幸福2025-01-14 16:00:17

最简单的方法不是创建一个您感兴趣的大小的字节数组吗?要获得非常大的分配,您可能需要使用这种技术使用多个数组。

另外,如果您愿意,您可以 p/invoke VirtualAlloc

如果你只需要一个应用程序,你也可以使用Testlimit系统内部。此实用程序用于 Mark Russinovich 的精彩突破 Windows 的极限系列。

Wouldn't the easiest way is just to create a byte array of the size you're interested in. To get very large allocations you may need to use more than one array using this technique.

Also if you're so inclinded you could p/invoke to VirtualAlloc

If you just need to an app you could also use Testlimit from sysinternals. This utility was used in Mark Russinovich's awesome Pushing the Limits of Windows series.

凹づ凸ル2025-01-14 16:00:17

根据您要寻找的“内存压力”:

  • boot.ini 刻录内存选项 - http://support.microsoft .com/kb/833721 真正限制可用内存量。
  • 创建一个简单地分配大量内存并主动访问它的程序。通过这种方式,您可以看到其他程序对内存分配/使用缓慢的反应。
  • 在您感兴趣的进程中分配内存,以对地址空间(主要是 32 位)造成压力。

Depending on what "memory pressure" you are looking for:

  • boot.ini burnmemory option - http://support.microsoft.com/kb/833721 to really restrict amount of available memory.
  • create a program that simply allocates large amount of memory and actively touches it. This way you can see how your other program reacts to slowness in memory allocation/usage.
  • allocate memory in the process you are interested to create pressure on address space (32-bit mostly).
痴情2025-01-14 16:00:17

一种方法是创建字节数组。将输入值从 MB 转换为字节,然后分配数组。如果您想直接尝试堆栈分配,可以使用stackalloc

One way of doing it could be creating an array of bytes. Convert your input value from MB to bytes and then allocate the array. If you want to try the stack allocation directly, you could use stackalloc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文