summaryrefslogtreecommitdiffstats
path: root/Whisper/CPU/LargeBuffer.cpp
diff options
context:
space:
mode:
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