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
}
}
Is there a way I can use PowerShell to do the same for maximizing memory usage?
Try this:
$mem_stress = "a" * 200MB
Edit: 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) }
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With