New tool to test for availability of virtual memory reserves.
authorMarcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de>
Fri, 6 Aug 2010 16:50:03 +0000 (18:50 +0200)
committerMarcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de>
Fri, 6 Aug 2010 16:50:03 +0000 (18:50 +0200)
virtual-alloc.c [new file with mode: 0644]

diff --git a/virtual-alloc.c b/virtual-alloc.c
new file mode 100644 (file)
index 0000000..b2f8444
--- /dev/null
@@ -0,0 +1,36 @@
+#include <windows.h>
+
+int
+main (int argc, char *argv[])
+{
+  int asize = 1024*1024*1024;
+  int total_high = 0;
+  int total_low = 0;
+
+  printf ("Trying size 0x%08x\n", asize);
+
+  while (asize >= 4096)
+    {
+      void *ptr;
+
+      ptr = VirtualAlloc (NULL, asize, MEM_RESERVE, PAGE_NOACCESS);
+      if (ptr != NULL)
+       {
+         printf ("Allocated region of size 0x%08x at 0x%p\n", asize, ptr);
+         if (ptr >= (void*)0x40000000)
+           total_high += asize;
+         else
+           total_low += asize;
+       }
+      else
+       {
+         asize /= 2;
+         printf ("Trying size 0x%08x\n", asize);
+       }
+    }
+  printf ("Total High: 0x%08x\n", total_high);
+  printf ("Total Low:  0x%08x\n", total_low);
+  Sleep (300);
+  return 0;
+}