home *** CD-ROM | disk | FTP | other *** search
- // You can place a handler on the free store allocation to globally
- // detect if the new operator correctly allocated memory.
- // NOTE: This is an old C++ 1.2 feature that we ported forward
- // to support old code. I would not recommend building a
- // large program around this feature as it is NOT
- // part of the C++ 2.0 specs.
-
- #include <iostream.h>
- #include <string.h>
- #include <process.h>
-
- // Declare the external new handler
- extern void (*_new_handler)();
-
- // Write the function to handler exhausted heap
- void heap_exhausted( void )
- {
- cout << "No remaining heap!\n";
- exit(1);
- }
-
- // Install the new handler
- // I have used a new TURBO C++ pragma to force the setup to happen
- // before main.
- void setup( void )
- {
- _new_handler = heap_exhausted;
- }
- #pragma startup setup 70
-
- // Here is a main that will exhaust the free store in the
- // small memory model.
- main()
- {
- char *one = new char[60000u];
- char *two = new char[60000u];
- strcmp(one, two);
-
- return 0;
- }
-