#pragma once #include #include typedef struct { void* ptr; size_t size; } MemoryBlock; static MemoryBlock allocations[10000]; static size_t allocation_count = 0; static inline void* my_malloc(size_t size) { void* ptr = malloc(size); if (ptr) { allocations[allocation_count++] = (MemoryBlock){ptr, size}; printf("Allocated: %zu bytes, Total Allocated: %zu blocks\n", size, allocation_count); } else { printf("Allocation failed for size: %zu bytes\n", size); } return ptr; } static inline void* my_calloc(size_t num, size_t size) { void* ptr = calloc(num, size); if (ptr) { allocations[allocation_count++] = (MemoryBlock){ptr, num * size}; printf("Allocated: %zu bytes (calloc), Total Allocated: %zu blocks\n", num * size, allocation_count); } else { printf("Allocation failed for size: %zu bytes (calloc)\n", num * size); } return ptr;} static inline void* my_realloc(void* ptr, size_t size) { void* new_ptr = realloc(ptr, size); if (new_ptr) { for (size_t i = 0; i < allocation_count; i++) { if (allocations[i].ptr == ptr) { allocations[i].ptr = new_ptr; allocations[i].size = size; printf("Reallocated: from %zu bytes to %zu bytes\n", allocations[i].size, size); break; } } } else { printf("Reallocation failed for size: %zu bytes\n", size); } return new_ptr; } static inline void my_free(void* ptr) { for (size_t i = 0; i < allocation_count; i++) { if (allocations[i].ptr == ptr) { printf("Freed: %zu bytes, Remaining Allocated: %zu blocks\n", allocations[i].size, allocation_count - 1); allocations[i] = allocations[--allocation_count]; break; } } free(ptr); } #define malloc(size) my_malloc(size) #define calloc(num, size) my_calloc(num, size) #define realloc(ptr, size) my_realloc(ptr, size) #define free(ptr) my_free(ptr)