home *** CD-ROM | disk | FTP | other *** search
- // ex03005.cpp
- // free store exhaustion and the _new_handler function
- #include <iostream.h>
- #include <stdlib.h>
-
- static void all_gone()
- {
- cerr << "\n\aThe free store is empty\n";
- exit(1);
- }
-
- extern void (*_new_handler)();
-
- main()
- {
- _new_handler = all_gone;
- long total = 0;
- while (1) {
- char *gobble = new char[10000];
- total += 10000;
- cout << "Got 10000 for a total of " << total << '\n';
- }
- }