Skip to content

Instantly share code, notes, and snippets.

@pdu
Last active February 17, 2017 04:05
Show Gist options
  • Save pdu/58ca2c4a74be95b2043a6c9b950d6aa2 to your computer and use it in GitHub Desktop.
Save pdu/58ca2c4a74be95b2043a6c9b950d6aa2 to your computer and use it in GitHub Desktop.
Eat memory program, have tested on Mac OSX
#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;
}
@pdu
Copy link
Author

pdu commented Feb 17, 2017

Compile:
$ g++ eat_memory.cpp -o eat_memory

Eat 10GB memory:
$ ./eat_memory 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment