custom new/delete
Posted: Wed Sep 15, 2021 1:11 pm
Hi,
I' trying to override the new/delete operators to add some data to any dynamically allocated memory, like this:
But the ESP32 errors (CORRUPT HEAP) and reboots. This does work on other compilers/architectures like MSC. What could be done to make this trick work?
I' trying to override the new/delete operators to add some data to any dynamically allocated memory, like this:
Code: Select all
void * operator new(size_t size)
{
size_t* ret = (size_t*)malloc(size + sizeof(size_t*));
*ret = 0;
ret++;
return (void*)ret;
}
void operator delete(void * ptr)
{
size_t* ptrmem = (size_t*)ptr;
ptrmem--;
free((void*)ptrmem);
}