xref: /aosp_15_r20/external/lzma/CPP/Windows/MemoryGlobal.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1*f6dc9357SAndroid Build Coastguard Worker // Windows/MemoryGlobal.cpp
2*f6dc9357SAndroid Build Coastguard Worker 
3*f6dc9357SAndroid Build Coastguard Worker #include "StdAfx.h"
4*f6dc9357SAndroid Build Coastguard Worker 
5*f6dc9357SAndroid Build Coastguard Worker #include "MemoryGlobal.h"
6*f6dc9357SAndroid Build Coastguard Worker 
7*f6dc9357SAndroid Build Coastguard Worker namespace NWindows {
8*f6dc9357SAndroid Build Coastguard Worker namespace NMemory {
9*f6dc9357SAndroid Build Coastguard Worker 
Alloc(UINT flags,SIZE_T size)10*f6dc9357SAndroid Build Coastguard Worker bool CGlobal::Alloc(UINT flags, SIZE_T size) throw()
11*f6dc9357SAndroid Build Coastguard Worker {
12*f6dc9357SAndroid Build Coastguard Worker   HGLOBAL newBlock = ::GlobalAlloc(flags, size);
13*f6dc9357SAndroid Build Coastguard Worker   if (newBlock == NULL)
14*f6dc9357SAndroid Build Coastguard Worker     return false;
15*f6dc9357SAndroid Build Coastguard Worker   _global = newBlock;
16*f6dc9357SAndroid Build Coastguard Worker   return true;
17*f6dc9357SAndroid Build Coastguard Worker }
18*f6dc9357SAndroid Build Coastguard Worker 
Free()19*f6dc9357SAndroid Build Coastguard Worker bool CGlobal::Free() throw()
20*f6dc9357SAndroid Build Coastguard Worker {
21*f6dc9357SAndroid Build Coastguard Worker   if (_global == NULL)
22*f6dc9357SAndroid Build Coastguard Worker     return true;
23*f6dc9357SAndroid Build Coastguard Worker   _global = ::GlobalFree(_global);
24*f6dc9357SAndroid Build Coastguard Worker   return (_global == NULL);
25*f6dc9357SAndroid Build Coastguard Worker }
26*f6dc9357SAndroid Build Coastguard Worker 
ReAlloc(SIZE_T size)27*f6dc9357SAndroid Build Coastguard Worker bool CGlobal::ReAlloc(SIZE_T size) throw()
28*f6dc9357SAndroid Build Coastguard Worker {
29*f6dc9357SAndroid Build Coastguard Worker   HGLOBAL newBlock = ::GlobalReAlloc(_global, size, GMEM_MOVEABLE);
30*f6dc9357SAndroid Build Coastguard Worker   if (newBlock == NULL)
31*f6dc9357SAndroid Build Coastguard Worker     return false;
32*f6dc9357SAndroid Build Coastguard Worker   _global = newBlock;
33*f6dc9357SAndroid Build Coastguard Worker   return true;
34*f6dc9357SAndroid Build Coastguard Worker }
35*f6dc9357SAndroid Build Coastguard Worker 
36*f6dc9357SAndroid Build Coastguard Worker }}
37