Created
March 27, 2013 16:18
-
-
Save seraphy/5255575 to your computer and use it in GitHub Desktop.
物理メモリを大量に消費させるメモリストレスツール。
第一引数は確保するメモリをメガバイトで指定する。
"java -Xmx4000 -cp . MemFill 3000" とすることで、3GBの物理メモリを確保しようとする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MemFill { | |
public static void main(String[] args) throws Exception { | |
if (args.length < 1) { | |
System.err.println("[usage] java -cp . MemFill <megabytes memory size>"); | |
System.err.println("[example] java -Xmx4000m -cp . MemFill 3000"); | |
System.exit(1); | |
} | |
int mega = 1024 * 1024; | |
int mx = Integer.parseInt(args[0]); | |
byte[][] bufs = new byte[mx][]; | |
for (int idx = 0; idx < mx; idx++) { | |
bufs[idx] = new byte[mega]; | |
System.console().printf("allocate %dMBytes\r", idx + 1); | |
} | |
System.console().printf("\r\ndone.\r\n"); | |
System.console().readLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment