From 9dae91f1993c563cf97a87b84836dc3b6306714a Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Fri, 15 Mar 2024 19:21:35 +0100 Subject: remove mem --- mem/mem.cpp | 85 ------------------------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 mem/mem.cpp (limited to 'mem/mem.cpp') diff --git a/mem/mem.cpp b/mem/mem.cpp deleted file mode 100644 index 43f5a89..0000000 --- a/mem/mem.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS - -#include -#include -#ifndef _WIN32 -#include -#endif -#pragma warning(disable : 4996) -void *debug_malloc(size_t size, const char* file, int line) { - void *p = malloc(size); - - if (p == NULL) { - return NULL; - } - - char buff[256]; - - sprintf(buff, "bin/debug/mem/%p.mem", p); - - FILE *f = fopen(buff, "w"); - if (!f) return p; - fprintf(f, "File: %s\nLine: %d\nSize: %zu bytes\n", file, line, size); - fclose(f); - - return p; -} - -void *debug_calloc(size_t count, size_t size, const char* file, int line) { - void *p = calloc(count, size); - - if (p == NULL) { - return NULL; - } - - char buff[256]; - - sprintf(buff, "bin/debug/mem/%p.mem", p); - - FILE *f = fopen(buff, "w"); - if (!f) return p; - - fprintf(f, "File: %s\nLine: %d\nSize: %zu bytes\n", file, line, - count * size); - fclose(f); - - return p; -} - -void *debug_realloc(void *ptr, size_t size, const char* file, int line) { - void *p = realloc(ptr, size); - - if (p == NULL) { - return NULL; - } - - char buff[256]; - //Delete the old pointer record - sprintf(buff, "bin/debug/mem/%p.mem", ptr); - if (ptr != NULL && unlink(buff) < 0) { - printf("Double free: %p File: %s Line: %d\n", ptr, file, line); - } - - //Create the new pointer record - sprintf(buff, "bin/debug/mem/%p.mem", p); - - FILE *f = fopen(buff, "w"); - if (!f) return p; - - fprintf(f, "File: %s\nLine: %d\nSize: %zu bytes\n", file, line, size); - fclose(f); - - return p; -} - -void debug_free(void *p, const char* file, int line) { - char buff[256]; - - sprintf(buff, "bin/debug/mem/%p.mem", p); - if (p != NULL && unlink(buff) < 0) { - printf("Double free: %p File: %s Line: %d\n", p, file, line); - } - - free(p); -} - -- cgit v1.2.3-70-g09d2