CMappedMemory::CMappedMemory(const TCHAR* FileName)
:	CFileAccess(FileName)
{
	SYSTEM_INFO sysinfo;

	m_AllocSize = 0;
	m_DirectFile = 0;
	m_FileMapping = 0;
	m_Base = NULL;

	GetSystemInfo(&sysinfo);
	m_AllocGranularity = sysinfo.dwAllocationGranularity; // usually 64kb
	m_MinAllocGranularity = m_AllocGranularity;           // must be at least one segment
	m_MaxAllocGranularity = m_AllocGranularity << 4;      // usually 1mb for fast increasing

	m_DirectFile = CreateFile(FileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, 0);
	if (m_DirectFile == INVALID_HANDLE_VALUE)
		LOGSYS(logCRITICAL, _T("CreateFile failed"));

	uint32_t size = GetFileSize(m_DirectFile, NULL);
	size = (size + m_AllocGranularity - 1) & ~(m_AllocGranularity - 1);

	if (size == 0)
		size = m_AllocGranularity;

	_SetSize(size);
	m_AllocSize = size;

	InitJournal();
}
Esempio n. 2
0
		Box::Box(Vector3D<double> pos, double width, double length, double height)
		{
			_SetType(BOX);
			_SetPos(pos);
			_SetSize(width, length, height);
			mSweepBox = SharedPtr<SweepBox>(new SweepBox);
		}
Esempio n. 3
0
uint32_t CFileAccess::Size(uint32_t NewSize)
{
	m_Size = NewSize;
	if (!m_Journal.Use)
	{
		NewSize = (NewSize + m_AllocGranularity - 1) & ~(m_AllocGranularity - 1);

		if (NewSize == 0)
			NewSize = m_AllocGranularity;

		if (NewSize != m_AllocSize)
		{
			m_AllocSize = _SetSize(NewSize);

			// adapt Alloc Granularity
			uint32_t t = _time32(NULL);
			uint32_t d = t - m_LastAllocTime;
			m_LastAllocTime = t;

			if (d < 30) // increase alloc stepping
			{
				if (m_AllocGranularity < m_MaxAllocGranularity)
					m_AllocGranularity = m_AllocGranularity << 1;
			} else if (d > 120) // decrease alloc stepping
			{
				if (m_AllocGranularity > m_MinAllocGranularity)
					m_AllocGranularity = m_AllocGranularity >> 1;
			}
		}
Esempio n. 4
0
		Box::Box(WeakPtr<SweepBox> sweepBox)
		{
			_SetType(BOX);
			_SetId(sweepBox.lock()->GetId());
			_SetPos(sweepBox.lock()->GetPos());
			_SetSize(sweepBox.lock()->GetWidth(), sweepBox.lock()->GetLength(), sweepBox.lock()->GetHeight());
			_SetVelocity(sweepBox.lock()->GetVelocity());//TODO this is probably unecessary, so optimize out
			mSweepBox = SharedPtr<SweepBox>(new SweepBox);
		}