overridding new and delete operators
- From: "Mr G" <mrg@xxxxxxxxxxxxxxxx>
- Date: Tue, 13 Mar 2007 12:22:31 -0000
Hi - I have a question regarding override of new and delete in visual studio
..NET 2003
I have overriden the operators globally as follows, as I have code which
expects NULL to be returned when memory fails to be allocated rather than
catching an exception
My question is do I also need to override new[] and delete[]. It looks as
though the compiler is already generating calls to my new and delete
functions.
//
// Function : operator new OVERRIDE
//
// Purpose : Override the "throwing" new operator
// : to make it return NULL on failure.
//
// Returns : void*
//
// Parameter : size_t size
//
void *__cdecl operator new(size_t size) _THROW1(std::bad_alloc)
{
void* pAlloc = malloc(size);
return pAlloc;
}
//
// Function : operator delete OVERRIDE
//
// Purpose : Override delete to free memory
// : allocated by the new override.
//
// Returns : void
//
// Parameter : none
//
void __cdecl operator delete(void* pAlloc) _THROW0()
{
free(pAlloc);
}
Many Thanks
Paul G
.
- Follow-Ups:
- Re: overridding new and delete operators
- From: Ulrich Eckhardt
- Re: overridding new and delete operators
- Prev by Date: Re: problem with debubtype
- Next by Date: Re: Samples
- Previous by thread: Re: problem with debubtype
- Next by thread: Re: overridding new and delete operators
- Index(es):
Relevant Pages
|