Invoke AfxThrowMemoryException cause "Access Violation"
I want to override the operator new in a class, as follows:
class CMyclass
{
public:
void* operator new(size_t);
void operator delete(void*);
};
void* CMyclass::operator new(size_t size)
{
void *p;
p = MemoryManager.Alloc(size); // Using customized memory manager to allocate buffer
if (NULL == p)
AfxThrowMemoryException();
}
However, in debug version, whenever MemoryManager.Alloc(size) returns NULL, which means alloation fails, the AfxThrowMemoryException will cause the following exception:
Access violation reading location 0x#######
How to fix the problem.
Re: Invoke AfxThrowMemoryException cause "Access Violation"
Do you catch somewhere the CMemoryException?
And please, edit your post adding the Code tags around code snippets!
Re: Invoke AfxThrowMemoryException cause "Access Violation"
Probably, the problem is inside MemoryManager::Alloc.
Anyway, MFC has overloaded new operators, enough smart. So, it has no much sense to overload your own, with the risk to lead in headaches, like the one from OP.