1.  
  2. /***
  3. *new.h - declarations and definitions for C++ memory allocation functions
  4. *
  5. *       Copyright (c) Microsoft Corporation. All rights reserved.
  6. *
  7. *Purpose:
  8. *       Contains the declarations for C++ memory allocation functions.
  9. *
  10. *       [Public]
  11. *
  12. ****/
  13.  
  14. #pragma once
  15.  
  16. #ifndef _INC_NEW
  17. #define _INC_NEW
  18.  
  19. #ifdef  __cplusplus
  20.  
  21. #ifndef _MSC_EXTENSIONS
  22. #include <new>
  23. #endif
  24.  
  25. #include <crtdefs.h>
  26.  
  27. /* Protect against #define of new */
  28. #pragma push_macro("new")
  29. #undef  new
  30.  
  31. /* Define _CRTIMP2 */
  32. #ifndef _CRTIMP2
  33. #if defined(_DLL) && !defined(_STATIC_CPPLIB)
  34. #define _CRTIMP2 __declspec(dllimport)
  35. #else   /* ndef _DLL && !STATIC_CPPLIB */
  36. #define _CRTIMP2
  37. #endif  /* _DLL && !STATIC_CPPLIB */
  38. #endif  /* _CRTIMP2 */
  39.  
  40. #ifdef  _MSC_EXTENSIONS
  41.  
  42. namespace std {
  43.  
  44. #ifdef _M_CEE_PURE
  45. typedef void (__clrcall * new_handler) ();
  46. #else
  47. typedef void (__cdecl * new_handler) ();
  48. #endif
  49. #ifdef _M_CEE
  50. typedef void (__clrcall * _new_handler_m) ();
  51. #endif
  52. _CRTIMP2 new_handler __cdecl set_new_handler(_In_opt_ new_handler _NewHandler) throw();
  53. };
  54.  
  55. #ifdef _M_CEE
  56. using std::_new_handler_m;
  57. #endif
  58. using std::new_handler;
  59. using std::set_new_handler;
  60. #endif
  61.  
  62. #ifndef __NOTHROW_T_DEFINED
  63. #define __NOTHROW_T_DEFINED
  64. namespace std {
  65.         /* placement new tag type to suppress exceptions */
  66.         struct nothrow_t {};
  67.  
  68.         /* constant for placement new tag */
  69.         extern const nothrow_t nothrow;
  70. };
  71.  
  72. _Ret_opt_bytecap_(_Size) void *__CRTDECL operator new(size_t _Size, const std::nothrow_t&) throw();
  73. _Ret_opt_bytecap_(_Size) void *__CRTDECL operator new[](size_t _Size, const std::nothrow_t&) throw();
  74. void __CRTDECL operator delete(void *, const std::nothrow_t&) throw();
  75. void __CRTDECL operator delete[](void *, const std::nothrow_t&) throw();
  76. #endif
  77.  
  78. #ifndef __PLACEMENT_NEW_INLINE
  79. #define __PLACEMENT_NEW_INLINE
  80. inline void *__CRTDECL operator new(size_t, void *_Where)
  81.         {return (_Where); }
  82. inline void __CRTDECL operator delete(void *, void *)
  83.         {return; }
  84. #endif
  85.  
  86.  
  87. /*
  88.  * new mode flag -- when set, makes malloc() behave like new()
  89.  */
  90.  
  91. _CRTIMP int __cdecl _query_new_mode( void );
  92. _CRTIMP int __cdecl _set_new_mode( _In_ int _NewMode);
  93.  
  94. #ifndef _PNH_DEFINED
  95. #ifdef _M_CEE_PURE
  96. typedef int (__clrcall * _PNH)( size_t );
  97. #else
  98. typedef int (__cdecl * _PNH)( size_t );
  99. #endif
  100. #define _PNH_DEFINED
  101. #endif
  102.  
  103. _CRTIMP _PNH __cdecl _query_new_handler( void );
  104. _CRTIMP _PNH __cdecl _set_new_handler( _In_opt_ _PNH _NewHandler);
  105.  
  106. /*
  107.  * Microsoft extension:
  108.  *
  109.  * _NO_ANSI_NEW_HANDLER de-activates the ANSI new_handler. Use this special value
  110.  * to support old style (_set_new_handler) behavior.
  111.  */
  112.  
  113. #ifndef _NO_ANSI_NH_DEFINED
  114. #define _NO_ANSI_NEW_HANDLER  ((new_handler)-1)
  115. #define _NO_ANSI_NEW_HANDLER_M  ((_new_handler_m)-1)
  116. #define _NO_ANSI_NH_DEFINED
  117. #endif
  118.  
  119. #pragma pop_macro("new")
  120.  
  121. #endif  /* __cplusplus */
  122.  
  123. #endif  /* _INC_NEW */