| 1 |
|
| 2 |
#include <xpa.h> |
| 3 |
#include <string.h> |
| 4 |
#include <setjmp.h> |
| 5 |
|
| 6 |
#define MAXB 1024 |
| 7 |
#define GB (1024 * 1024 * 1024) |
| 8 |
|
| 9 |
char *xmalloc(int size); |
| 10 |
void xfree(char *buf); |
| 11 |
|
| 12 |
int main(int argc, char **argv) |
| 13 |
{ |
| 14 |
char iter=0; |
| 15 |
int i=0; |
| 16 |
int n=0; |
| 17 |
char tbuf[100]; |
| 18 |
char *bufs[MAXB]; |
| 19 |
jmp_buf env; |
| 20 |
|
| 21 |
loop: |
| 22 |
iter++; |
| 23 |
if( setjmp(env) == 0 ){ |
| 24 |
XPASaveJmp((void *)env); |
| 25 |
fprintf(stdout, "continue? "); |
| 26 |
fgets(tbuf, 99, stdin); |
| 27 |
if( *tbuf != 'y' ){ |
| 28 |
fprintf(stdout, "exiting ...\n"); |
| 29 |
return 0; |
| 30 |
} |
| 31 |
else{ |
| 32 |
fprintf(stderr, "allocating ...\n"); |
| 33 |
for(n=0; n<MAXB; n++){ |
| 34 |
bufs[n] = (char *)xmalloc(GB); |
| 35 |
memset(bufs[n], iter, GB); |
| 36 |
fprintf(stderr, "%d\n", n); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
else{ |
| 41 |
for(i=0; i<n+1; i++){ |
| 42 |
if( bufs[i] ) xfree(bufs[i]); |
| 43 |
} |
| 44 |
n = 0; |
| 45 |
fprintf(stderr, "freed up memory for next iteration\n"); |
| 46 |
goto loop; |
| 47 |
} |
| 48 |
return 0; |
| 49 |
} |