summaryrefslogtreecommitdiffstats
path: root/Whisper/CPU/LargeBuffer.cpp
blob: e12468623dde7aa5f6d0eed5fc2ba6fb53d14793 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}