Skip to content

Instantly share code, notes, and snippets.

@royhaddad
Created December 21, 2015 22:07
Show Gist options
  • Save royhaddad/2ca33dde39c53ab6a0e1 to your computer and use it in GitHub Desktop.
Save royhaddad/2ca33dde39c53ab6a0e1 to your computer and use it in GitHub Desktop.
namespace CSharpNatural
{
unsafe static class Program
{
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
static extern void* VirtualAlloc(void* lpAddress,
uint dwSize,
uint flAllocationType,
uint flProtect);
const uint MEM_COMMIT = 0x00001000;
const uint MEM_RESERVE = 0x00002000;
const uint PAGE_READWRITE = 0x04;
static int Main()
{
const uint MemoryToAllocate = 64 * 1048576;
int ExitCode = 0;
byte *Memory = (byte*) VirtualAlloc((void*) 0,
MemoryToAllocate,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
if (Memory != (byte*) 0)
{
// YESSSSSSS
}
else
{
ExitCode = 1;
}
return ExitCode;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment