New operator overload in windows

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

//Global new and delete overload
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) // did malloc succeed?
        throw std::bad_alloc(); // ANSI/ISO compliant behavior
    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) // did malloc succeed?
        throw std::bad_alloc(); // ANSI/ISO compliant behavior
    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.

+3
source share
1 answer

/ ++ tar baby. , , , .

, " " " ", , , , DLL, "" , . , . , .

/ , . , , /delete .

"" , - . , - (, ) 2- Linux valgrind.

+7

All Articles