Quick Memory Allocation for Limit / Reservation Testing in VMware

I am testing the impact and behavior of memory limits and reservations along with balloon drivers and I needed a quick way to allocate memory in a user program.

PowerShell to the rescue. This isn’t a good method for exact memory allocation, but you can consume MBs to GBs of memory pretty quickly.

# Allocate memory by creating a large string.  Divide the length by 4
# (Unicode size) to get an approximation of the MB allocation. Make
# sure to assign the result to a variable otherwise the memory will be
# reclaimed to the .Net garbage collector
$a = "a" * 256MB/4

Leave a Comment

Your email address will not be published.