diff --git a/README.md b/README.md index f235539..fc17ff6 100644 --- a/README.md +++ b/README.md @@ -4,20 +4,20 @@ it allocates memory ## how to use -``` -usage: allocatememory -b [-o ] [-s] - -OPTIONS - -h displays help - -b number of bytes to allocate (e.g. 1024, 1g, 64K) - -o file to output to - -s run silently (requires -b and -o) - -w disable warnings ("i know what i'm doing!") -``` +- run the executable +- enter how much memory you want to allocate + - i.e. "1g" = 1 GiB = 1073741824 bytes + - the limit is how much memory you have...or more. your funeral. +- confirm (y) +- wait for the program to allocate the memory +- your memory is allocated +- press ENTER or CTRL+C to free the memory and exit the program +- ??? +- profit ## how to compile -- get a c compiler (i use gcc or clang) +- get a c compiler (i use gcc) - `gcc -o ./allocatememory -O2 ./main.c` - ??? - profit diff --git a/main.c b/main.c index 317d945..c6c3801 100644 --- a/main.c +++ b/main.c @@ -7,7 +7,7 @@ #include #define BYTES_GIVEN 1 -#define OUTPUT_FILE 2 +#define FILENAME_GIVEN 2 #define SILENT 4 #define BYPASS_WARN 8 @@ -52,7 +52,7 @@ int main(int argc, char* argv[]) { break; case 'o': filename = optarg; - flags |= OUTPUT_FILE; + flags |= FILENAME_GIVEN; break; case 's': if (size == 0 || filename == NULL) { @@ -100,7 +100,6 @@ int main(int argc, char* argv[]) { } unsigned long long int* heap = allocate_heap(size, flags & SILENT); - if (filename != NULL) save_heap(heap, size, filename, flags & SILENT); if (!(flags & SILENT)) { if (shorthand) { @@ -116,6 +115,10 @@ int main(int argc, char* argv[]) { exit(0); } + if (filename != NULL) save_heap(heap, size, filename, SILENT); + + if (!(flags & SILENT)) printf("done!\n"); + free(heap); return 0; @@ -205,6 +208,20 @@ void save_heap(unsigned long long int* heap, unsigned long long int size, char* printf("failed to open %s!", filename); exit(1); } + + if (!silent) printf("please wait...\n"); + /* + for (unsigned long long int i = 0; i < size / sizeof(unsigned long long int); i++) { + for (int p = 0; p < 8; p++) { + fputc(*(&heap[i] + p), file); + } + if (i > 0 && i % (1024 * 1024 * 1024 / sizeof(long long int)) == 0) { + if (!silent) printf("."); + fflush(stdout); + } + } + if (!silent) printf("\n"); + */ fwrite(heap, sizeof(char), size, file); fputs("\n", file); fclose(file);