Hi,
I am currently writing a small custom memory Allocator in c++, and want to use it together with operator overloading of new/delete. Anyways, my memory Allocator basicall checks if the requested memory is over a certain threshold, and if so uses malloc to allocate the requested memory chunk. Otherwise the memory will be provided by some fixedPool allocators. that generally works, but for my deallocation function looks like this:
void MemoryManager::deallocate(void * _ptr, size_t _size){
if(_size heapThreshold)
deallocHeap(_ptr);
else
deallocFixedPool(_ptr, _size);
}
so I need to provide the size of the chunk pointed to, to deallocate from the right place.
No the problem is that the delete keyword does not provide any hint on the size of the deleted chunk, so I would need something like this:
void operator delete(void * _ptr, size_t _size){ MemoryManager::deallocate(_ptr, _size); }
But as far as I can see, there is no way to determine the size inside the delete operator.- If I want to keep things the way it is right now, would I have to save the size of the memory chunks myself?
Any ideas on how to solve this are welcome! Thanks!