alloc.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 2k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //+-------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //
  5. //  Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. //  File:       alloc.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _INC_CSCVIEW_ALLOC_H
  11. #define _INC_CSCVIEW_ALLOC_H
  12. //////////////////////////////////////////////////////////////////////////////
  13. /*  File: alloc.h
  14.     Description: Installs a "new handler" that throws CMemoryException
  15.         when a memory allocation request fails.  Required since our
  16.         compiler doesn't throw bad_alloc on memory alloc failures.
  17.     Revision History:
  18.     Date        Description                                          Programmer
  19.     --------    ---------------------------------------------------  ----------
  20.     10/20/97    Initial creation.                                    BrianAu
  21. */
  22. ///////////////////////////////////////////////////////////////////////////////
  23. //
  24. // Currently, USE_NEW_HANDLER is undefined.  Defining a new handler affects
  25. // memory allocation behavior for each thread in a process.  Since the
  26. // viewer code could be (most likely is) running on another thread,
  27. // I didn't want to cause the throwing of exceptions to code that isn't
  28. // prepared to handle those exceptions.  Therefore, I've opted for overloading
  29. // global new and delete which is bound at compile time to the viewer modules
  30. // only (which are exception-aware).  [brianau - 12/8/97]
  31. //
  32. #ifdef USE_NEW_HANDLER
  33. #ifndef _INC_NEW
  34. #   include <new.h>
  35. #endif
  36. class NewHandler
  37. {
  38.     public:
  39.         NewHandler(void)
  40.             { _set_new_handler(HandlerFunc); }
  41.     private:
  42.         static int __cdecl HandlerFunc(size_t size)
  43.             { throw CException(ERROR_OUTOFMEMORY); return 0;}
  44. };
  45. #endif // USE_NEW_HANDLER
  46. //
  47. // Declarations for overloading global new and delete.
  48. //
  49. void * __cdecl operator new(size_t size);
  50. void __cdecl operator delete(void *ptr) throw();
  51. #endif // _CSCVIEW_ALLOC_H