Skip to content

Instantly share code, notes, and snippets.

@pdu
Created February 17, 2017 04:03
Show Gist options
  • Select an option

  • Save pdu/366d163d61e9dd171660effcef9652f0 to your computer and use it in GitHub Desktop.

Select an option

Save pdu/366d163d61e9dd171660effcef9652f0 to your computer and use it in GitHub Desktop.
$ g++ eat_memory.cpp -o eat_memory
#include <stdlib.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char** argv) {
size_t size = atoi(argv[1]) * 1024LL * 1024LL * 1024LL;
printf("%lu\n", size);
void *ptr = malloc(size);
memset(ptr, 0xff, size);
mlock(ptr, size);
int c;
scanf("%d", &c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment