You can use a simple C program to allocate or try to allocate arbitrary amounts of memory on the heap:
#include <stdio.h> #include <stdlib.h> #define MB (1024*1024) #define DEFAULT_ALLOC ((size_t) (512*MB)); int main(int argc, char *argv[]) { char buffer[2]; char *chunk; char *endp; size_t howmuch; if ( argc < 2 ) { howmuch = DEFAULT_ALLOC; } else { howmuch = strtoul(argv[1], &endp, 10); if ( *endp ) { fputs("Failed to parse command line argument", stderr); howmuch = DEFAULT_ALLOC; } else { howmuch *= MB; } } chunk = calloc(howmuch, 1); if ( chunk == NULL ) { fputs("Memory allocation error", stderr); exit(EXIT_FAILURE); } puts("Memory allocated.\nPress ENTER to terminate program"); fgets(buffer, 2, stdin); return EXIT_SUCCESS; }
Sinan ΓnΓΌr
source share