home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / CPPTUTOR / HANDLER.CP$ / HANDLER
Encoding:
Text File  |  1991-12-12  |  581 b   |  29 lines

  1. // HANDLER.CPP
  2.  
  3. // This is an example program from Chapter 6 of the C++ Tutorial. This
  4. //     program demonstrates free store exhaustion and the
  5. //     _set_new_handler function.
  6.  
  7. #include <iostream.h>
  8. #include <new.h>
  9. #include <stdlib.h>
  10.  
  11. int all_gone( size_t size )
  12. {
  13.    cerr << "The free store is empty\n";
  14.    exit( -1 );
  15.    return 0;
  16. }
  17.  
  18. void main()
  19. {
  20.    _set_new_handler( all_gone );
  21.    long total = 0;
  22.    while( 1 )
  23.    {
  24.       char *gobble = new char[10000];
  25.       total += 10000;
  26.       cout << "Got 10000 for a total of " << total << '\n';
  27.    }
  28. }
  29.