I am trying to replace the global operator new and delete. On Linux this works fine, but on Windows (MSVC 10) it is sometimes allocated using the system version of the new operator, and then tries to free it using my delete operator. Since I retain some contextual information during distribution, my delete statement expects the same during release. How would I make sure that windows constantly raise my operator?
edit: I tried different things. This ad
void* operator new (std::size_t bytes) throw(...);
void operator delete(void* p) throw();
void* operator new( std::size_t size, const std::nothrow_t&) throw();
void operator delete( void* mem, const std::nothrow_t&) throw();
void* operator new[] ( std::size_t bytes) throw(...);
void operator delete[](void* p) throw();
void* operator new[]( std::size_t size, const std::nothrow_t&) throw();
void operator delete[](void* mem, const std::nothrow_t&) throw();
#ifdef WIN32
void *__CRTDECL operator new(std::size_t size) _THROW1(_STD bad_alloc);
#endif
These are the definitions.
#ifdef WIN32
void *__CRTDECL operator new(std::size_t bytes) _THROW1(_STD bad_alloc)
{
void* p = edb::g_getCurrentMemoryContext()->alloc(bytes);
if (p==0)
throw std::bad_alloc();
return p;
}
#endif
void operator delete(void* p) throw()
{
edb::MemContext::free(p);
}
void* operator new( std::size_t bytes, const std::nothrow_t&) throw()
{
return edb::g_getCurrentMemoryContext()->alloc(bytes);
}
void operator delete(void* p, const std::nothrow_t&) throw()
{
edb::MemContext::free(p);
}
void* operator new[] ( std::size_t bytes) throw(...)
{
void* p = edb::g_getCurrentMemoryContext()->alloc(bytes);
if (p==0)
throw std::bad_alloc();
return p;
}
void operator delete[](void* p) throw()
{
edb::MemContext::free(p);
}
void* operator new[]( std::size_t bytes, const std::nothrow_t&) throw()
{
return edb::g_getCurrentMemoryContext()->alloc(bytes);
}
void operator delete[](void* p, const std::nothrow_t&) throw()
{
edb::MemContext::free(p);
}
And sometimes he picks up my definitions, and sometimes not.
Thanks, Gokul.
Gokul source
share