From 8c4603c73675958efc960fbd4bb599a2909d106a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 16 Jan 2023 14:52:43 +0100 Subject: Source codes --- Whisper/CPU/LargeBuffer.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Whisper/CPU/LargeBuffer.cpp (limited to 'Whisper/CPU/LargeBuffer.cpp') 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 -- cgit v1.2.3