OLD | NEW |
(Empty) | |
| 1 #pragma once |
| 2 //------------------------------------------------------------------------------
------------------- |
| 3 // <copyright file="memutil.cpp" company="Outercurve Foundation"> |
| 4 // Copyright (c) 2004, Outercurve Foundation. |
| 5 // This software is released under Microsoft Reciprocal License (MS-RL). |
| 6 // The license and further copyright text can be found in the file |
| 7 // LICENSE.TXT at the root directory of the distribution. |
| 8 // </copyright> |
| 9 // |
| 10 // <summary> |
| 11 // Memory helper functions. |
| 12 // </summary> |
| 13 //------------------------------------------------------------------------------
------------------- |
| 14 |
| 15 #include "../precomp.h" |
| 16 |
| 17 |
| 18 #if DEBUG |
| 19 static BOOL vfMemInitialized = FALSE; |
| 20 #endif |
| 21 |
| 22 extern "C" HRESULT DAPI MemInitialize() |
| 23 { |
| 24 #if DEBUG |
| 25 vfMemInitialized = TRUE; |
| 26 #endif |
| 27 return S_OK; |
| 28 } |
| 29 |
| 30 extern "C" void DAPI MemUninitialize() |
| 31 { |
| 32 #if DEBUG |
| 33 vfMemInitialized = FALSE; |
| 34 #endif |
| 35 } |
| 36 |
| 37 extern "C" LPVOID DAPI MemAlloc( |
| 38 __in SIZE_T cbSize, |
| 39 __in BOOL fZero |
| 40 ) |
| 41 { |
| 42 // AssertSz(vfMemInitialized, "MemInitialize() not called, this would normall
y crash"); |
| 43 AssertSz(cbSize > 0, "MemAlloc() called with invalid size"); |
| 44 return ::HeapAlloc(::GetProcessHeap(), fZero ? HEAP_ZERO_MEMORY : 0, cbSize)
; |
| 45 } |
| 46 |
| 47 |
| 48 extern "C" LPVOID DAPI MemReAlloc( |
| 49 __in LPVOID pv, |
| 50 __in SIZE_T cbSize, |
| 51 __in BOOL fZero |
| 52 ) |
| 53 { |
| 54 // AssertSz(vfMemInitialized, "MemInitialize() not called, this would normall
y crash"); |
| 55 AssertSz(cbSize > 0, "MemReAlloc() called with invalid size"); |
| 56 return ::HeapReAlloc(::GetProcessHeap(), fZero ? HEAP_ZERO_MEMORY : 0, pv, c
bSize); |
| 57 } |
| 58 |
| 59 |
| 60 extern "C" HRESULT DAPI MemFree( |
| 61 __in LPVOID pv |
| 62 ) |
| 63 { |
| 64 // AssertSz(vfMemInitialized, "MemInitialize() not called, this would normall
y crash"); |
| 65 return ::HeapFree(::GetProcessHeap(), 0, pv) ? S_OK : HRESULT_FROM_WIN32(::G
etLastError()); |
| 66 } |
| 67 |
| 68 |
| 69 extern "C" SIZE_T DAPI MemSize( |
| 70 __in LPCVOID pv |
| 71 ) |
| 72 { |
| 73 // AssertSz(vfMemInitialized, "MemInitialize() not called, this would normall
y crash"); |
| 74 return ::HeapSize(::GetProcessHeap(), 0, pv); |
| 75 } |
OLD | NEW |