#ifndef XGMEM_H #define XGMEM_H // Visual C++ fix of operator new // // Global overwrite of new, delete // // On some systems even malloc throws the std::bad_alloc exception // Could override the default handler and then do your own handler #include <stdlib.h> // for malloc, free #include <iostream> using std::cout; using std::endl; #include <exception> // for std::bad_alloc using std::bad_alloc; #include <new> // for size_t void* operator new (size_t size) { cout << "Attempting allocating " << size << " bytes" << endl; void *p = malloc(size); cout << "Allocating memory of size " << size << " bytes" << endl; if (p==0) // did malloc succeed? cout << "Memory exception thrown for " << size << " bytes" << endl; throw std::bad_alloc(); // ANSI/ISO compliant behavior return p; } void operator delete (void *p) { free(p); } #endif XGMEM_H
Hosted by www.Geocities.ws

1