blob: 435ea9994e9de5470a4687ff7c357543c931feb4 (
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
60
61
62
63
64
|
// Windows/Memory.cpp
#include "StdAfx.h"
#include "Windows/Memory.h"
namespace NWindows {
namespace NMemory {
CGlobal::~CGlobal()
{
Free();
}
bool CGlobal::Alloc(UINT flags, SIZE_T size)
{
HGLOBAL newBlock = ::GlobalAlloc(flags, size);
if (newBlock == NULL)
return false;
m_MemoryHandle = newBlock;
return true;
}
bool CGlobal::Free()
{
if (m_MemoryHandle == NULL)
return true;
m_MemoryHandle = ::GlobalFree(m_MemoryHandle);
return (m_MemoryHandle == NULL);
}
void CGlobal::Attach(HGLOBAL hGlobal)
{
Free();
m_MemoryHandle = hGlobal;
}
HGLOBAL CGlobal::Detach()
{
HGLOBAL h = m_MemoryHandle;
m_MemoryHandle = NULL;
return h;
}
LPVOID CGlobal::Lock() const
{
return ::GlobalLock(m_MemoryHandle);
}
void CGlobal::Unlock() const
{
::GlobalUnlock(m_MemoryHandle);
}
bool CGlobal::ReAlloc(SIZE_T size)
{
HGLOBAL newBlock = ::GlobalReAlloc(m_MemoryHandle, size, GMEM_MOVEABLE);
if (newBlock == NULL)
return false;
m_MemoryHandle = newBlock;
return true;
}
}}
|