LCD-show/usr/fbcp-ili9341/mem_alloc.cpp
2021-01-27 08:18:51 +00:00

25 lines
669 B
C++

#include "config.h"
#include "mem_alloc.h"
#include <memory.h>
#include <stdlib.h>
#include <stdio.h>
uint64_t totalCpuMemoryAllocated = 0;
void *Malloc(size_t bytes, const char *reason)
{
void *ptr = malloc(bytes);
if (ptr)
{
totalCpuMemoryAllocated += bytes; // Currently we don't decrement this, so this only counts up (all allocations are persistent so far, so that's ok for now)
// printf("Allocated %zd bytes of CPU memory for %s. Total memory allocated: %llu bytes\n", bytes, reason, totalCpuMemoryAllocated);
return ptr;
}
else
{
printf("Failed to allocate %zd bytes of memory for %s!\n", bytes, reason);
exit(1);
}
}