Last active
December 14, 2015 07:29
-
-
Save shalecraig/5051161 to your computer and use it in GitHub Desktop.
Kill your computer with this quick memory allocation. Thrashing guaranteed, or your money back.
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
#include <cstdlib> | |
#include <stdio.h> | |
#include <sys/mman.h> | |
int main() { | |
char buffer[100]; | |
int n; | |
// 16 GB * 1000 | |
void* allRam = malloc(17179869184*1000); | |
printf("allocated \n"); | |
n = sprintf(buffer, "%d", mlock(allRam, 17179869184 * 1000)); | |
printf("result is %s, %d length\n", buffer, n); | |
return 0; | |
} |
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
curl -O https://gist.github.com/shalecraig/5051161/raw/test.cpp && gcc test.cpp && ./a.out |
Author
shalecraig
commented
Feb 27, 2013
- Allocate a lot of ram.
- Force it to be locked in memory (and not swapped out of it).
- Laugh while you watch your computer transfer as much of your memory to ram as possible.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment