blob: faef99345920ce48f302e2bb190b0135c125ae95 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Windows/Memory.cpp
#include "StdAfx.h"
#include "Windows/Memory.h"
namespace NWindows {
namespace NMemory {
CGlobal::~CGlobal()
{
Free();
}
// aFlags = GMEM_MOVEABLE
bool CGlobal::Alloc(UINT aFlags, DWORD aSize)
{
HGLOBAL aNewBlock = ::GlobalAlloc(aFlags, aSize);
if (aNewBlock == NULL)
return false;
m_MemoryHandle = aNewBlock;
return true;
}
bool CGlobal::Free()
{
if (m_MemoryHandle == NULL)
return true;
m_MemoryHandle = ::GlobalFree(m_MemoryHandle);
return (m_MemoryHandle == NULL);
}
HGLOBAL CGlobal::Detach()
{
HGLOBAL aHandle = m_MemoryHandle;
m_MemoryHandle = NULL;
return aHandle;
}
LPVOID CGlobal::Lock() const
{
return ::GlobalLock(m_MemoryHandle);
}
void CGlobal::Unlock() const
{
::GlobalUnlock(m_MemoryHandle);
}
bool CGlobal::ReAlloc(DWORD aSize)
{
HGLOBAL aNewBlock = ::GlobalReAlloc(m_MemoryHandle, aSize, GMEM_MOVEABLE);
if (aNewBlock == NULL)
return false;
m_MemoryHandle = aNewBlock;
return true;
}
}}
|