summaryrefslogtreecommitdiffstats
path: root/Whisper/CPU/LargeBuffer.cpp
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-01-16 14:52:43 +0100
committerKonstantin <const@const.me>2023-01-16 14:52:43 +0100
commit8c4603c73675958efc960fbd4bb599a2909d106a (patch)
tree714dc6fc9a1672d5fd7f89676b97e10959662abc /Whisper/CPU/LargeBuffer.cpp
parent990a8d0dbaefc996244097397259e92758b15cce (diff)
Source codes
Diffstat (limited to 'Whisper/CPU/LargeBuffer.cpp')
-rw-r--r--Whisper/CPU/LargeBuffer.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/Whisper/CPU/LargeBuffer.cpp b/Whisper/CPU/LargeBuffer.cpp
new file mode 100644
index 0000000..e124686
--- /dev/null
+++ b/Whisper/CPU/LargeBuffer.cpp
@@ -0,0 +1,34 @@
+#include "stdafx.h"
+#include "LargeBuffer.h"
+using namespace CpuCompute;
+
+void LargeBuffer::deallocate()
+{
+ if( nullptr == pv )
+ return;
+ VirtualFree( pv, 0, MEM_RELEASE );
+ pv = nullptr;
+}
+
+HRESULT LargeBuffer::allocate( size_t cb )
+{
+ deallocate();
+
+ pv = VirtualAlloc( nullptr, cb, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE );
+ if( nullptr != pv )
+ return S_OK;
+ return HRESULT_FROM_WIN32( GetLastError() );
+}
+
+HRESULT LargeBuffer::setReadOnly( size_t cb )
+{
+ if( nullptr != pv )
+ {
+ DWORD op = 0;
+ if( VirtualProtect( pv, cb, PAGE_READONLY, &op ) )
+ return S_OK;
+ return HRESULT_FROM_WIN32( GetLastError() );
+ }
+ else
+ return OLE_E_BLANK;
+} \ No newline at end of file