Imported Upstream version 9.20
[platform/upstream/7zip.git] / CPP / Windows / Memory.cpp
1 // Windows/Memory.cpp\r
2 \r
3 #include "StdAfx.h"\r
4 \r
5 #include "Windows/Memory.h"\r
6 \r
7 namespace NWindows {\r
8 namespace NMemory {\r
9 \r
10 bool CGlobal::Alloc(UINT flags, SIZE_T size)\r
11 {\r
12   HGLOBAL newBlock = ::GlobalAlloc(flags, size);\r
13   if (newBlock == NULL)\r
14     return false;\r
15   m_MemoryHandle = newBlock;\r
16   return true;\r
17 }\r
18 \r
19 bool CGlobal::Free()\r
20 {\r
21   if (m_MemoryHandle == NULL)\r
22     return true;\r
23   m_MemoryHandle = ::GlobalFree(m_MemoryHandle);\r
24   return (m_MemoryHandle == NULL);\r
25 }\r
26 \r
27 bool CGlobal::ReAlloc(SIZE_T size)\r
28 {\r
29   HGLOBAL newBlock = ::GlobalReAlloc(m_MemoryHandle, size, GMEM_MOVEABLE);\r
30   if (newBlock == NULL)\r
31     return false;\r
32   m_MemoryHandle = newBlock;\r
33   return true;\r
34 }\r
35 \r
36 }}\r