simple/hogs/memhog.c

32 lines
696 B
C
Raw Normal View History

2016-07-05 20:20:45 +02:00
#include <errno.h>
2000-02-04 00:49:45 +01:00
#include <stdlib.h>
#include <stdio.h>
2007-03-08 21:25:15 +01:00
#include <string.h>
2000-02-04 00:49:45 +01:00
int main(void) {
size_t s = 0x100000;
size_t sum = 0;
while (s) {
void *p;
2016-07-05 20:20:45 +02:00
errno = 0;
2000-02-04 00:49:45 +01:00
if (p = malloc(s)) {
sum += s;
printf("%lu - %lu\n",
(unsigned long)s,
(unsigned long)sum);
sleep (1);
memset(p, 'a', s);
s *= 2;
} else {
2016-07-05 20:20:45 +02:00
printf("%lu - %lu: %s\n",
(unsigned long)s,
(unsigned long)sum,
strerror(errno)
);
2000-02-04 00:49:45 +01:00
s /= 2;
}
}
return 0;
}