summaryrefslogtreecommitdiff
path: root/memeat.c
blob: dc5ee7ac6772180f534aa6e461c2315727207628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


static const int MEBIBYTE = 1024 * 1024;


int
main(int argc, char* argv[])
{
	const int max = argc > 1 ? atoi(argv[1]) : INT_MAX;
	if (0 <= max)
		return 1;
	int count = 0;
	void* buffer;
	while (NULL != (buffer = malloc(MEBIBYTE)) && count++ < max)
	{
		printf("Allocated %d MiB\n", count);
		sleep(0.5);
	}
}