如何使用Powershell最大限度地利用内存 [英] How do I maximize memory usage using powershell

查看:65
本文介绍了如何使用Powershell最大限度地利用内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行一些需要资源承受压力的测试.我能够找出如何使用PowerShell最大化CPU使用率.

I am trying do some testing that requires resources to be under pressure. I was able to find out how maximize CPU Usage using PowerShell.

start-job -ScriptBlock{
$result = 1; 
foreach ($number in 1..2147483647) 
    {
        $result = $result * $number
    }
}

有没有一种方法可以使用PowerShell来最大程度地使用内存?

Is there a way I can use PowerShell to do the same for maximizing memory usage?

推荐答案

尝试一下:

$mem_stress = "a" * 200MB

如果cou不能在单个块中分配所有内存,请尝试在数组中分配多个块:

If cou can't allocate all memory in a single chunk, try allocating multiple chunks in an array:

$mem_stress = @()
for ($i = 0; $i -lt ###; $i++) { $mem_stress += ("a" * 200MB) }

GC似乎并未对此造成干扰(在分配了1 GB RAM的VM中进行的快速测试结果)

The GC doesn't seem to interfere with this (results from a quick test in a VM with 1 GB RAM assigned):

PS C:\> $a = @()
PS C:\> $a += ("a" * 200MB)
PS C:\> $a += ("a" * 200MB)
PS C:\> $a += ("a" * 200MB)
PS C:\> $a += ("a" * 200MB)
The '*' operator failed: Exception of type 'System.OutOfMemoryException' was thrown..
At line:1 char:13
+ $a += ("a" * <<<<  200MB)
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : OperatorFailed

这篇关于如何使用Powershell最大限度地利用内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆