I have wrote a cpp as follow to overload the new operator.
void* operator new(size_t size)
{
//return malloc(size);
return MemoryMgr::Instance().allocMem(size);
}
void operator delete(void* p)
{
MemoryMgr::Instance().freeMem(p);
}
void* operator new[](size_t size)
{
return MemoryMgr::Instance().allocMem(size);
}
void operator delete[](void* p)
{
MemoryMgr::Instance().freeMem(p);
}
void* mem_alloc(size_t size)
{
return MemoryMgr::Instance().allocMem(size);
}
void mem_free(void* p)
{
free(p);
}
However, in the main function, sometime I want to ues original new. But the computer always calls the overloaded new. Then I have tried the ::new
.But it doesn't make sense. Which way that I can use both overloaded new and original new ? Put the void* operator new in a specialized class which need to be overload new function?
Aucun commentaire:
Enregistrer un commentaire