#pragma once
// WAC.com Class Liblary for Visual C++
// Copyright (C) WAC.com Inc. All rights reserved.
//
// This file is a part of the WAC.com Class Liblary.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license. You must not remove this notice, or
// any other, from this software.
// '04.03.24 : 新規作成 (sha)
// '06.04.14 : CVirtualAllocator::Reallocate() の修正 (sug)
// '07.03.20 : CVirtualAllocator::VirtualFreeのNULLチェック(AppVerifier対応)(imatsu)
// '07.04.06 : コードの整備 (sha)
// '07.05.16 : Reallocateの仕様を、VC8に準拠 (sha)
////////////////////////////////////////////////////////////////////////////////
// CFixedGlobalAllocator
// 修正版のCGlobalAllocator
class CFixedGlobalAllocator
{
public:
static void* Allocate(size_t nBytes) throw()
{
return ::GlobalAlloc(GMEM_FIXED, nBytes);
}
static void* Reallocate(void* p, size_t nBytes) throw()
{
#if (_MSC_VER >= 1400) // VS2005
if (p==NULL){
return ( Allocate(nBytes) );
}
if (nBytes==0){
Free(p);
return NULL;
}
#endif
#if 0 // 元のCGlobalAllocatorのコード
return ( ::GlobalReAlloc(p, nBytes, 0) );
#else
return ( ::GlobalReAlloc(p, nBytes, GMEM_MOVEABLE) );
#endif
}
static void Free(void* p) throw()
{
::GlobalFree(p);
}
};