Hello people,
I am writing a memory pool application and I have the below problem:
When I start, the application is allocating (by using malloc) a big amount of memory. Then, a list of char pointers point to different places of the allocated memory. When I call allocate, one of these pointers is returned.
The problem is, when I call deallocate, I only want to explicitly call the destructor of the object and then make the memory block available again. In other words, I do not want to free the memory.
So my deallocate looks like that:
void Pool:: Deallocate(void* pObj)
{
.. Call object destructor here ..
m_ListOfSlices.push_back((char*)pObj);
m_AllocLeft += 1;
}
How can I call the destructor of the object that
pObj
points to?
Keep in mind that I do not really want a template solution.
There must be a way, since operator delete, is actually doing the same thing! I tried to debug the operator delete, but I had no luck.
Please help!
Revised:::
Thanks very much for your answers,
To answer answer 1, I am afraid you can actually do that. You can actually do
pMem->~A();
and then call
delete pMem;
To question answer2, I have read the parashift tutorials long ago, the problem is that they do not apply to my situation at all ;) . I am trying to do a different thing. Thanks very much for the reply though :)