2010-05-25 09:15:19 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
CRecompMemory::CRecompMemory() :
|
2010-05-30 01:54:42 +00:00
|
|
|
m_RecompCode(NULL),
|
2010-05-25 09:15:19 +00:00
|
|
|
m_RecompSize(0)
|
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
m_RecompPos = NULL;
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CRecompMemory::~CRecompMemory()
|
|
|
|
{
|
|
|
|
if (m_RecompCode)
|
|
|
|
{
|
|
|
|
VirtualFree( m_RecompCode, 0 , MEM_RELEASE);
|
|
|
|
m_RecompCode = NULL;
|
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
m_RecompPos = NULL;
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CRecompMemory::AllocateMemory()
|
|
|
|
{
|
|
|
|
BYTE * RecompCodeBase = (BYTE *)VirtualAlloc( NULL, MaxCompileBufferSize + 4, MEM_RESERVE|MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE);
|
2010-06-04 06:25:07 +00:00
|
|
|
if (RecompCodeBase==NULL)
|
2010-05-25 09:15:19 +00:00
|
|
|
{
|
|
|
|
_Notify->DisplayError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-04 06:25:07 +00:00
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
m_RecompCode = (BYTE *)VirtualAlloc( RecompCodeBase, InitialCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
2010-06-04 06:25:07 +00:00
|
|
|
if (m_RecompCode==NULL)
|
2010-05-25 09:15:19 +00:00
|
|
|
{
|
|
|
|
VirtualFree( RecompCodeBase, 0 , MEM_RELEASE);
|
|
|
|
_Notify->DisplayError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
m_RecompSize = InitialCompileBufferSize;
|
2010-05-30 01:54:42 +00:00
|
|
|
m_RecompPos = m_RecompCode;
|
2010-06-12 02:02:06 +00:00
|
|
|
memset(m_RecompCode,0,InitialCompileBufferSize);
|
2010-05-25 09:15:19 +00:00
|
|
|
return true;
|
2010-05-30 01:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompMemory::CheckRecompMem ( void )
|
|
|
|
{
|
|
|
|
int Size = (int)((BYTE *)m_RecompPos - (BYTE *)m_RecompCode);
|
|
|
|
if ((Size + 0x20000) < m_RecompSize)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_RecompSize == MaxCompileBufferSize)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LPVOID MemAddr = VirtualAlloc( m_RecompCode + m_RecompSize , IncreaseCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
m_RecompSize += IncreaseCompileBufferSize;
|
|
|
|
|
|
|
|
if (MemAddr == NULL)
|
|
|
|
{
|
|
|
|
_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
2010-06-12 02:02:06 +00:00
|
|
|
|
|
|
|
void CRecompMemory::Reset()
|
|
|
|
{
|
|
|
|
m_RecompPos = m_RecompCode;
|
2010-06-16 07:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompMemory::ShowMemUsed()
|
|
|
|
{
|
|
|
|
DWORD Size = m_RecompPos - m_RecompCode;
|
|
|
|
DWORD MB = Size / 0x100000;
|
|
|
|
Size -= MB * 0x100000;
|
|
|
|
DWORD KB = Size / 1024;
|
|
|
|
Size -= KB * 1024;
|
|
|
|
|
|
|
|
DWORD TotalAvaliable = m_RecompSize / 0x100000;
|
|
|
|
|
|
|
|
DisplayMessage(0,"Memory used: %d mb %-3d kb %-3d bytes Total Available: %d mb",MB,KB,Size, TotalAvaliable);
|
2010-06-12 02:02:06 +00:00
|
|
|
}
|