// Heap.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "UtilErr.h"	// For FFThrowMiscUnknown.
#include "UtilFile.h"	// For FFMakeUniqTmpFileName.
#include "HeapBuffer.h"	// For FCHeapBuffer.
#include "HeapPool.h"	// This header.

//----- 05.12.24 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
//#ifdef _DEBUG
//#define new DEBUG_NEW
//#undef THIS_FILE
//static char THIS_FILE[] = __FILE__;
//#endif
//----- 05.12.24 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----

/////////////////////////////////////////////////////////////////////////////
//
// _xZkqqHx_iDhEiDeAiDeDiDiLiDhBiBfLiDhGiDgPiDgCiDhEiDeAiCmMiNfMjBkC_xHqqkZx_
//
//  m_pHeapBuffer
//        _xZkqqHx_iEkA_xHqqkZx_
//        _xZkqqHx_iBkL_xHqqkZx_
//        _xZkqqHx_iEkBiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEjPiEjPiEjPiEkC_xHqqkZx_
//        _xZkqqHx_iEkA_xHqqkZx_hFile _xZkqqHx_iEkA_xHqqkZx_BufSiz_xZkqqHx_iEkA_xHqqkZx_ File Path  _xZkqqHx_iEkA_xHqqkZx_
//        _xZkqqHx_iEkEiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEjPiEjPiEjPiEkD_xHqqkZx_
//            _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iBkL_xHqqkZx_
//          HeapTop                                                         LastSegmentEnd
//            _xZkqqHx_iEkA_xHqqkZx_                                                                  _xZkqqHx_iEkA_xHqqkZx_    HeapEnd
//            _xZkqqHx_iEkFiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_1Segment_xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEkJiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_1Segment_xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEkH_xHqqkZx_      _xZkqqHx_iBkL_xHqqkZx_
//            _xZkqqHx_iEkBiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiBgD_xHqqkZx_  _xZkqqHx_iBgDiEkGiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiBgD_xHqqkZx_  _xZkqqHx_iBgDiEkGiEjPiEjPiEjPiEkGiBgD_xHqqkZx_  _xZkqqHx_iBgDiEjPiEjPiEjPiEjPiEjPiEkC_xHqqkZx_
//            _xZkqqHx_iEkA_xHqqkZx_Size1 _xZkqqHx_iEkA_xHqqkZx_RefCnt_xZkqqHx_iEkA_xHqqkZx_DataId_xZkqqHx_iEkA_xHqqkZx_  Data  _xZkqqHx_iEkA_xHqqkZx_Size2 _xZkqqHx_iEkA_xHqqkZx_RefCnt_xZkqqHx_iEkA_xHqqkZx_DataId_xZkqqHx_iEkA_xHqqkZx_  Data  _xZkqqHx_iEkA_xHqqkZx_  0   _xZkqqHx_iEkA_xHqqkZx_        JUNK    _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iEkEiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiBgD_xHqqkZx_  _xZkqqHx_iBgDiEkIiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiBgD_xHqqkZx_  _xZkqqHx_iBgDiEkIiEjPiEjPiEjPiEkIiBgD_xHqqkZx_  _xZkqqHx_iBgDiEjPiEjPiEjPiEjPiEjPiEkD_xHqqkZx_
//            _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_        _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_        _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iEkF_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJiEjPiEjPiEjPiEjPiEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJiEjPiEjPiEjPiEjPiEkJ_xHqqkZx_DWORD _xZkqqHx_iEkH_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iEkA_xHqqkZx_                                _xZkqqHx_iEkA_xHqqkZx_                                _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iEkFiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_Size1 _xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEjPiEkJiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_Size2 _xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEjPiEkH_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iEkA_xHqqkZx_                                                                          _xZkqqHx_iEkA_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iEkFiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_ BufSiz _xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEkH_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iEkA_xHqqkZx_                                                                                            _xZkqqHx_iEkA_xHqqkZx_
//            _xZkqqHx_iEkFiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_ File Size -_xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEkH_xHqqkZx_
//
//
// _xZkqqHx_iDiBiDiCiDiKiBfLiDhBiBfLiDhGiDgPiDgCiDhEiDeAiCmMiNfMjBkC_xHqqkZx_
//
//          m_pHeapBuffer
//                _xZkqqHx_iEkA_xHqqkZx_
//                _xZkqqHx_iBkL_xHqqkZx_
//              HeapTop                                                         LastSegmentEnd
//                _xZkqqHx_iEkA_xHqqkZx_                                                                  _xZkqqHx_iEkA_xHqqkZx_    HeapEnd
//                _xZkqqHx_iEkFiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_1Segment_xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEkJiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_1Segment_xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEkH_xHqqkZx_      _xZkqqHx_iBkL_xHqqkZx_
//        _xZkqqHx_iEkBiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiBgD_xHqqkZx_  _xZkqqHx_iBgDiEkGiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiEjPiEjPiEkGiEjPiBgD_xHqqkZx_  _xZkqqHx_iBgDiEkGiEjPiEjPiEjPiEkGiBgD_xHqqkZx_  _xZkqqHx_iBgDiEjPiEjPiEjPiEjPiEjPiEkC_xHqqkZx_
//        _xZkqqHx_iEkA_xHqqkZx_BufSiz_xZkqqHx_iEkA_xHqqkZx_Size1 _xZkqqHx_iEkA_xHqqkZx_RefCnt_xZkqqHx_iEkA_xHqqkZx_DataId_xZkqqHx_iEkA_xHqqkZx_  Data  _xZkqqHx_iEkA_xHqqkZx_Size2 _xZkqqHx_iEkA_xHqqkZx_RefCnt_xZkqqHx_iEkA_xHqqkZx_DataId_xZkqqHx_iEkA_xHqqkZx_  Data  _xZkqqHx_iEkA_xHqqkZx_  0   _xZkqqHx_iEkA_xHqqkZx_        JUNK    _xZkqqHx_iEkA_xHqqkZx_
//        _xZkqqHx_iEkEiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiBgD_xHqqkZx_  _xZkqqHx_iBgDiEkIiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiEjPiEjPiEkIiEjPiBgD_xHqqkZx_  _xZkqqHx_iBgDiEkIiEjPiEjPiEjPiEkIiBgD_xHqqkZx_  _xZkqqHx_iBgDiEjPiEjPiEjPiEjPiEjPiEkD_xHqqkZx_
//        _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_        _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_        _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//        _xZkqqHx_iEkF_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJiEjPiEjPiEjPiEjPiEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJ_xHqqkZx_DWORD _xZkqqHx_iEkJiEjPiEjPiEjPiEjPiEkJ_xHqqkZx_DWORD _xZkqqHx_iEkH_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//                _xZkqqHx_iEkA_xHqqkZx_                                _xZkqqHx_iEkA_xHqqkZx_                                _xZkqqHx_iEkA_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//                _xZkqqHx_iEkFiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_Size1 _xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEjPiEkJiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_Size2 _xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEjPiEkH_xHqqkZx_      _xZkqqHx_iEkA_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//                _xZkqqHx_iEkA_xHqqkZx_                                                                          _xZkqqHx_iEkA_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//                _xZkqqHx_iEkFiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_ BufSiz _xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEkH_xHqqkZx_                _xZkqqHx_iEkA_xHqqkZx_
//                _xZkqqHx_iEkA_xHqqkZx_                                                                                            _xZkqqHx_iEkA_xHqqkZx_
//                _xZkqqHx_iEkFiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjP_xHqqkZx_ FD_MEMORY_HEAP_SIZE -_xZkqqHx_iEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEjPiEkH_xHqqkZx_
//
//
/////////////////////////////////////////////////////////////////////////////
// FCHeapPool

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::FCHeapPool
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDfIiDgHiDiJiDeOiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
FCHeapPool::FCHeapPool ()
		:	m_dwMemoryBufferCount(0)
{
} // FCHeapPool::FCHeapPool.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::GetFirstId
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhBiBfLiDhGiDhGiBfLiDiLjCiGiCmMiNmFiPiJiCmMiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDhBiBfLiDhGiDhGiBfLiDiLjCiGiCmMiNmFiPiJiCmMiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
DWORD FCHeapPool::GetFirstId ()
{
	DWORD dwId = m_vHeapTypePool.size();
	for (dwId--; dwId != DWORD(-1); dwId--)
	{
		if (m_vHeapTypePool[dwId] != FD_BUFFER_TYPE_NONE)
			break;
	}
	return dwId;
} // FCHeapPool::GetFirstId.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::GetNextId
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iOhHjCoIiClDiCoKiClNiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCmMiOjPiCmMjHeMiMpIiCmIiDgPiDgCiDhEiDeAiCmM_xHqqkZx_ID_xZkqqHx_iCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	dwHeapBufferId	:_xZkqqHx_iDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iOjPiCmMiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iBeCjHeMiMpIiCmIiDgPiDgCiDhEiDeAiCkKjGlDiCkCiPoKiNiHiCmN_xHqqkZx_DWORD(-1)_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
DWORD FCHeapPool::GetNextId (DWORD dwHeapBufferId)
{
	DWORD dwId = dwHeapBufferId;
	for (dwId--; dwId != DWORD(-1); dwId--)
	{
		if (m_vHeapTypePool[dwId] != FD_BUFFER_TYPE_NONE)
			break;
	}
	return dwId;
} // FCHeapPool::GetNextId.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::AppendBuffer
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhBiBfLiDhGiDgPiDgCiDhEiDeAiCpAiDhGiBfLiDiLiCmJjCmHiJmBiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	dwDataSize	:_xZkqqHx_iDgGiBfLiDfOiDfEiDeDiDfJiCpAiOhHjCoIiBeCiNoMjAkMiClDiCoKiCoJiDgPiDgCiDhEiDeAiCmMiDfOiDeDiDhGiCpA_xHqqkZx_
 *						 _xZkqqHx_iMiIiCnPiCoJiClNiCnPiCmMiOfBiNgMiCmJiOgHiCoNiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jCmHiJmBiClDiCoKiClNiDgPiDgCiDhEiDeAiCmM_xHqqkZx_ID_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
DWORD FCHeapPool::AppendBuffer (DWORD dwDataSize)
{
	// _xZkqqHx_iOgHiCoNiCoKiCmEiCkCiCmIiCkCiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCpAjCfEiClHiBeC_xHqqkZx_
	DWORD dwId = GetFreeId();
	if (dwDataSize < FCHeapBuffer::GetMaxBufferSize(FD_BUFFER_TYPE_MEMORY) / 3)
	//----- _xZkqqHx_iDgGiBfLiDfOiDfEiDeDiDfJiCkKiDiBiDiCiDiKiBfLiDhBiBfLiDhGiDfEiDeDiDfJiCoGiCoIiPfMjFkKiPkMiClDiCkCiPoKiNiH_xHqqkZx_ -----
	{
		m_vHeapTypePool[dwId] = FD_BUFFER_TYPE_MEMORY;
		// _xZkqqHx_iDiBiDiCiDiKiBfLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCmMiNiHiMhGjAjEiCpAiJmBiOfKiBeC_xHqqkZx_
		m_dwMemoryBufferCount++;
	} else
	//----- _xZkqqHx_iDgGiBfLiDfOiDfEiDeDiDfJiCkKjEoEiKhCjDeJjBoFiCkLiCkCiPoKiNiH_xHqqkZx_ -----
	{
		m_vHeapTypePool[dwId] = FD_BUFFER_TYPE_FILE;
	}
	m_vHeapPool[dwId] = FCHeapBuffer::CreateHeapBuffer(m_vHeapTypePool[dwId]);
	return dwId;
} // FCHeapPool::AppendBuffer.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::DeleteBuffer
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iOhHjCoIiClDiCoKiClNiDgPiDgCiDhEiDeAiCpAiNoNiPjMiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	dwHeapBufferId	:_xZkqqHx_iDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCHeapPool::DeleteBuffer (DWORD dwHeapBufferId)
{
	// _xZkqqHx_iDiBiDiCiDiKiBfLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCmMiNiHiMhGjAjEiCpAiMlIiOfKiBeC_xHqqkZx_
	if (m_vHeapTypePool[dwHeapBufferId] == FD_BUFFER_TYPE_MEMORY)
		m_dwMemoryBufferCount--;
	FCHeapBuffer::DeleteHeapBuffer(m_vHeapTypePool[dwHeapBufferId], m_vHeapPool[dwHeapBufferId]);
	m_vHeapTypePool[dwHeapBufferId] = FD_BUFFER_TYPE_NONE;
	m_vHeapPool[dwHeapBufferId] = NULL;
} // FCHeapPool::DeleteBuffer.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::GetHeapBuffer
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCkJiCoHiBeBiDgPiDgCiDhEiDeAiDeOiDiJiDfIiDeJiDhFiDfHiDeGiDeOiDgHiCpAiNoMjAkMiClFiCmEjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	dwHeapBufferId	:_xZkqqHx_iDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDgPiDgCiDhEiDeAiDeOiDiJiDfIiDeJiDhFiDfHiDeGiDeOiDgHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_iDhGiDiNiDePiDiJiDiAjHjIjFnGjAkLiCmMiClNiCnPiCmJjHhAiInDiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
FCHeapBuffer FCHeapPool::GetHeapBuffer (DWORD dwHeapBufferId) const
{
	return FCHeapBuffer(m_vHeapTypePool[dwHeapBufferId], m_vHeapPool[dwHeapBufferId]);
} // FCHeapPool::GetHeapBuffer.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::GetMemoryBufferSize
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiBiDiCiDiKiBfLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCkKjAoIiCnPiCoJiNiHiMhGiDgPiDeDiDgHjAjEiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDiBiDiCiDiKiBfLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCmMiNiHiMhGiDgPiDeDiDgHjAjEiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_iMlFjGkHiCmFiCmNiCmIiCkCiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
DWORD FCHeapPool::GetMemoryBufferSize () const
{
	return (m_dwMemoryBufferCount * FCHeapBuffer::GetMaxBufferSize(FD_BUFFER_TYPE_MEMORY));
} // FCHeapPool::GetMemoryBufferSize.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::ChangeMemoryTypeToFileType
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jBfDiCmEiCmMiDiBiDiCiDiKiBfLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCpAiBeBiDhEiDeAiDeDiDiLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCmJjDfNiKlHiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	stBufferId	:_xZkqqHx_jAfGiClFiCkNiNoMjAkMiClDiCoKiClNiDhEiDeAiDeDiDiLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCmM_xHqqkZx_ID_xZkqqHx_iCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_jFkBjAjEiCmMiDiBiDiCiDiKiBfLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCkKiIoKiCmCiCmMiDhEiDeAiDeDiDiLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCmJ_xHqqkZx_
 *			_xZkqqHx_iCnMiCmGiCnPiCoHiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCHeapPool::ChangeMemoryTypeToFileType (DWORDSet& stBufferId)
{
	// _xZkqqHx_iDiBiDiCiDiKiBfLiDfOiDeDiDhGiCmMiDgPiDgCiDhEiDeAiCkKjBlGiNnNiClFiCmIiCkCiPoKiNiHiCmNjFjMiLeBiBeC_xHqqkZx_
	if (m_dwMemoryBufferCount == 0) return;
	// _xZkqqHx_jAfGiLeLiCmJiNoMjAkMiClDiCoKiCoJiDhEiDeAiDeDiDiLiDfOiDeDiDhGiCmMiDgPiDgCiDhEiDeAjEhKjHpBiBeC_xHqqkZx_
	vector<void*> vFileHeapBuffer;
	vFileHeapBuffer.push_back(FCHeapBuffer::CreateHeapBuffer(FD_BUFFER_TYPE_FILE));
	DWORD dwHeapBufferId;
	for (dwHeapBufferId = GetFirstId();
		 dwHeapBufferId != DWORD(-1);
		 dwHeapBufferId = GetNextId(dwHeapBufferId))
	{
		if (m_vHeapTypePool[dwHeapBufferId] == FD_BUFFER_TYPE_MEMORY)
		//----- _xZkqqHx_iDiBiDiCiDiKiBfLiDfOiDeDiDhGiCmMiDgPiDgCiDhEiDeAiCmMiPoKiNiH_xHqqkZx_ -----
		{
			// _xZkqqHx_iDgPiDgCiDhEiDeAjFmPjAjEiCpAiNoMjAkMiBeC_xHqqkZx_
			FCHeapBuffer memoryHeapBuffer = GetHeapBuffer(dwHeapBufferId);
			if (FCHeapBuffer(FD_BUFFER_TYPE_FILE, vFileHeapBuffer.back()).GetRestBufferSize() < memoryHeapBuffer.GetBufferSize())
			//----- _xZkqqHx_jFkBiOmKjAoGiCmMiDhEiDeAiDeDiDiLiDfOiDeDiDhGiCmMiDgPiDgCiDhEiDeAiCmMiOgDiCoIiDfEiDeDiDfJiCkKjFkBiOmKiMlDiDgPiDgCiDhEiDeAiCpAiOpLiCnPiCoJiCmJjBkLiCoIiCmIiCkCiPoKiNiH_xHqqkZx_ -----
			{
				// _xZkqqHx_jAfGiClFiCkNiDhEiDeAiDeDiDiLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCpAiNoMjAkMiBeC_xHqqkZx_
				vFileHeapBuffer.push_back(FCHeapBuffer::CreateHeapBuffer(FD_BUFFER_TYPE_FILE));
			}
			// _xZkqqHx_jFkBiOmKjAoGiCmMiDhEiDeAiDeDiDiLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCmJjFkBiOmKiMlDiCmMiDiBiDiCiDiKiBfLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCpAjCmHiJmBiBeC_xHqqkZx_
			FCHeapBuffer(FD_BUFFER_TYPE_FILE, vFileHeapBuffer.back()).Append(memoryHeapBuffer);
			// _xZkqqHx_iDiBiDiCiDiKiBfLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCpAiNoNiPjMiBeC_xHqqkZx_
			DeleteBuffer(dwHeapBufferId);
		}
	}
	vector<void*>::iterator i;
	for (i = vFileHeapBuffer.begin(); i != vFileHeapBuffer.end(); i++)
	{
		// _xZkqqHx_iOgHiCoNiCoKiCmEiCkCiCmIiCkCiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCpAjCfEiClHiBeC_xHqqkZx_
		DWORD dwId = GetFreeId();
		stBufferId.insert(dwId);
		// _xZkqqHx_iNoMjAkMiClDiCoKiClNiDhEiDeAiDeDiDiLiDfOiDeDiDhGiDgPiDgCiDhEiDeAiCpAjAnNjCoIiBeC_xHqqkZx_
		m_vHeapTypePool[dwId] = FD_BUFFER_TYPE_FILE;
		m_vHeapPool[dwId] = *i;
	}
} // FCHeapPool::ChangeMemoryTypeToFileType.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCHeapPool::GetFreeId
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iOgHiCoNiCoKiCmEiCkCiCmIiCkCiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iOgHiCoNiCoKiCmEiCkCiCmIiCkCiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.12.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
DWORD FCHeapPool::GetFreeId ()
{
	DWORD dwId;
	// _xZkqqHx_iOgHiCoNiCoKiCmEiCkCiCmIiCkCiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCpAjCfEiClHiBeC_xHqqkZx_
	for (dwId = 0; dwId != m_vHeapTypePool.size(); dwId++)
	{
		if (m_vHeapTypePool[dwId] == FD_BUFFER_TYPE_NONE)
			break;
	}
	if (dwId == m_vHeapTypePool.size())
	//----- _xZkqqHx_iOgHiCoNiCoKiCmEiCkCiCmIiCkCiDgPiDgCiDhEiDeA_xHqqkZx_ID_xZkqqHx_iCkKjGlDiCkCiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_iDgPiDgCiDhEiDeAjEhKjHpBiCmMiNmFiMoDiCmJjCmHiJmBiBeC_xHqqkZx_
		m_vHeapTypePool.push_back(FD_BUFFER_TYPE_NONE);
		m_vHeapPool.push_back(NULL);
	}
	return dwId;
} // FCHeapPool::GetFreeId.

