#include "MemoryManager.h" #include #include #include static int KB = 1024; static int MB = 1048576; int main(void) { char* ptr; int* intValue; // Test FIRST_FIT if ( !InitializeMemory(FIRST_FIT, 4 * MB, 0) ) { fprintf(stderr, "Error: Could not initialize memory with size %d\n", 4*MB); exit(-1); } if ( !MyMalloc( 400 * KB, (void**)(&ptr) ) ) { fprintf(stderr, "Error: Could not allocate memory\n"); exit(-1); } if (ptr) { memset(ptr, 2, 200 * KB); // Initialize the memory to some value if ( !MyMalloc(sizeof(int), (void**)(&intValue) )) exit(-1); *intValue = 200; PrintMemory(); // Print out the current state of memory MyFree((void**)(&ptr)); // Free the memory allocated MyFree((void**)(&intValue)); } TerminateMemory(); // Stop and free-up the current memory allocation algorithm // Test other allocation algorithms here too (with or without compaction) // InitializeMemory(BEST_FIT, 2 * MB, 1) return 0; }