what if Malloc also printed the pointer address?

This commit is contained in:
maksw committed 2025-12-01 22:42:32 +01:00
1 parent 39db8ed41f
commit dfda091f9a
3 files changed
+4 -1

No files matched your search

Binary file not shown.
Binary file not shown.
+4 -1
View File
@@ -117,7 +117,7 @@ static bool IsPointerInPool(void* ptr) {
} }
void* Malloc(size_t size) { void* Malloc(size_t size) {
PRINT(L"Allocating memory of size %ull\n", size); PRINT(L"Allocating memory of size %llu, ptr = ", size);
size = ALIGN_UP(size, AVX_ALIGN); // ensure AVX alignment size = ALIGN_UP(size, AVX_ALIGN); // ensure AVX alignment
struct BlockHeader* best = 0; struct BlockHeader* best = 0;
struct BlockHeader* bestPrev = 0; struct BlockHeader* bestPrev = 0;
@@ -136,6 +136,7 @@ void* Malloc(size_t size) {
} }
if (!best) { if (!best) {
PRINT(L"NULL\n");
return 0; return 0;
} }
@@ -145,6 +146,7 @@ void* Malloc(size_t size) {
size_t totalNeeded = size + padding; size_t totalNeeded = size + padding;
if (best->size < totalNeeded) { if (best->size < totalNeeded) {
PRINT(L"NULL not enough space\n");
return 0; // not enough space return 0; // not enough space
} }
@@ -163,6 +165,7 @@ void* Malloc(size_t size) {
best->free = false; best->free = false;
best->size = totalNeeded; best->size = totalNeeded;
PRINT(L"%p\n", (void*)alignedAddr);
return (void*)alignedAddr; return (void*)alignedAddr;
} }