Created
June 4, 2013 23:19
-
-
Save EmilienM/5710449 to your computer and use it in GitHub Desktop.
C script that consumes memory, 512M per 512M, every time it runs, it'll consume 512M of RAM:
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 <stdio.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define K 1024 | |
#define M 1024*K | |
#define MAX_MEM 500 | |
#define BLK_SIZE M | |
int main() { | |
uint8_t *p = malloc(MAX_MEM*1024*1024); | |
unsigned long i=0; | |
if (!p) { | |
printf("argh!\n"); | |
return 1; | |
} | |
for (i=0;i<MAX_MEM;i++) { | |
printf("MB=%ld\n",i); | |
memset(p,0,1024*1024); | |
p+=BLK_SIZE; | |
} | |
while(1) { | |
sleep(10); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment