I am currently writing a small custom Allocator memory block in C ++ and want to use it along with overloading the new / delete operator. In any case, my Allocator memory basically checks to see if the requested memory exceeds a certain threshold, and if so, malloc is used to allocate the requested piece of memory. Otherwise, memory will be provided by some fixedPool . which usually works, but for my highlight function is called:
void MemoryManager::deallocate(void * _ptr, size_t _size){ if(_size > heapThreshold) deallocHeap(_ptr); else deallocFixedPool(_ptr, _size); }
So, I need to specify the size of the selected fragment in order to free up space in the right place.
Now the problem is that the delete keyword does not contain any hint at the size of the fragment to be deleted, so I will need something like this:
void operator delete(void * _ptr, size_t _size){ MemoryManager::deallocate(_ptr, _size); }
But as far as I can tell, there is no way to determine the size inside the delete statement. If I want everything to be as it is now, I must save the size of the pieces of memory myself
source share