Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.0 KiB

  1. //==========================================================================
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright 1998 - 1999 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------
  11. #include "precomp.h"
  12. //+-------------------------------------------------------------------
  13. //
  14. // Function: ::operator new
  15. //
  16. // Synopsis: Our operator new implementation
  17. //
  18. // Arguments: [size] -- Size of memory to allocate
  19. //
  20. //
  21. // Notes:
  22. //
  23. //--------------------------------------------------------------------
  24. inline void* __cdecl operator new (size_t size)
  25. {
  26. return(ALLOC(size));
  27. }
  28. //+-------------------------------------------------------------------
  29. //
  30. // Function: ::operator delete
  31. //
  32. // Synopsis: Our operator deleteimplementation
  33. //
  34. // Arguments: lpv-- Pointer to memory to free
  35. //
  36. //
  37. // Notes:
  38. //
  39. //--------------------------------------------------------------------
  40. inline void __cdecl operator delete(void FAR* lpv)
  41. {
  42. FREE(lpv);
  43. }
  44. //+---------------------------------------------------------------------------
  45. //
  46. // function: ALLOC, public
  47. //
  48. // Synopsis: memory allocator
  49. //
  50. // Arguments: [cb] - requested size of memory to alloc.
  51. //
  52. // Returns: Pointer to newly allocated memory, NULL on failure
  53. //
  54. // Modifies:
  55. //
  56. //----------------------------------------------------------------------------
  57. LPVOID ALLOC(ULONG cb)
  58. {
  59. void *pv;
  60. pv = LocalAlloc(LMEM_FIXED,cb);
  61. #ifdef _DEBUG
  62. if (NULL != pv) // under debug always initialize to -1 to catch unitialize errors.
  63. {
  64. memset(pv,MEMINITVALUE,cb);
  65. }
  66. #endif // _DEBUG
  67. return pv;
  68. }
  69. //+---------------------------------------------------------------------------
  70. //
  71. // function: FREE, public
  72. //
  73. // Synopsis: memory destructor
  74. //
  75. // Arguments: [pv] - pointer to memory to be released.
  76. //
  77. // Returns:
  78. //
  79. // Modifies:
  80. //
  81. //----------------------------------------------------------------------------
  82. void FREE(void* pv)
  83. {
  84. #ifdef _DEBUG
  85. if (NULL != pv) // under debug always initialize to -1 to catch unitialize errors.
  86. {
  87. UINT cb;
  88. Assert(LMEM_INVALID_HANDLE != LocalFlags(pv));
  89. cb = LocalSize(pv); // returns zero on failure
  90. memset(pv,MEMFREEVALUE,cb);
  91. }
  92. Assert(pv);
  93. #endif // _DEBUG
  94. LocalFree(pv);
  95. }
  96. //+---------------------------------------------------------------------------
  97. //
  98. // function: REALLOC, public
  99. //
  100. // Synopsis: reallocs memory
  101. //
  102. // Arguments: [pv] - pointer to memory to be released.
  103. // [cb] - size to resize the memory to.
  104. //
  105. // Returns:
  106. //
  107. // Modifies:
  108. //
  109. //----------------------------------------------------------------------------
  110. LPVOID REALLOC(void *pv,ULONG cb)
  111. {
  112. Assert(pv);
  113. pv = LocalReAlloc(pv,cb,LMEM_MOVEABLE);
  114. return pv;
  115. }