BOOL CIndexedDataFiles::WriteNew(CIndexedDataDescriptor* pcIndexDescriptor, void* pvData)
{
	CIndexedFile*	pcIndexedFile;
	filePos			iIndex;
	int				iDataSize;

	iDataSize = pcIndexDescriptor->GetDataSize();
	if (iDataSize != 0)
	{
		pcIndexedFile = GetOrCreateFile(iDataSize);

		iIndex = pcIndexedFile->Write(pvData);
		if (iIndex == -1)
		{
			return FALSE;
		}

		pcIndexDescriptor->SetIndexes(pcIndexedFile->GetFileIndex(), iIndex);
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
Пример #2
0
void* CNamedIndexes::AllocateInCache(size_t iSize)
{
	CMemoryCacheAllocation		cPreAllocated;
	void*						pvData;
	int							i;
	SMemoryCacheDescriptor*		psMemoryDesc;
	int							iCacheDescriptorSize;
	CNamedIndexesBlock*			pcNamedIndexes;
	void*						pvCacheMem;
	CIndexedFile*				pcFile;
	BOOL						bResult;
	CNamedIndexesBlocks*		pcBlocks;

	cPreAllocated.Init(iSize);
	if (!mcCache.PreAllocate(&cPreAllocated))
	{
		cPreAllocated.Kill();
		return NULL;
	}

	for (i = 0; i < cPreAllocated.NumElements(); i++)
	{
		psMemoryDesc = cPreAllocated.Get(i);
		iCacheDescriptorSize = psMemoryDesc->iDataSize;
		pcBlocks = GetBlockForCacheDescriptorSize(iCacheDescriptorSize);
		if (!pcBlocks)
		{
			return NULL;
		}

		pvCacheMem = RemapSinglePointer(psMemoryDesc, sizeof(SMemoryCacheDescriptor));
		pcNamedIndexes = pcBlocks->GetBlock(pvCacheMem);
		if (!pcNamedIndexes)
		{
			return NULL;
		}

		pcFile = GetOrCreateFile(pcBlocks->GetDataSize(), pcBlocks->GetFileNumber());
		if (!pcFile)
		{
			return NULL;
		}
		pcBlocks->SetFileNumber(pcFile->miFileNumber);

		bResult = pcNamedIndexes->Uncache(pcFile);
		if (!bResult)
		{
			cPreAllocated.Kill();
			return NULL;
		}
	}

	pvData = mcCache.Allocate(&cPreAllocated);

	cPreAllocated.Kill();

	return pvData;
}
Пример #3
0
void Cl3::UpdateFromDir(const boost::filesystem::path& dir)
{
    for (auto& e : boost::filesystem::directory_iterator(dir))
        GetOrCreateFile(e.path().filename().string()).src =
            MakeSmart<DumpableSource>(Source::FromFile(e));

    for (auto it = entries.begin(); it != entries.end(); )
        if (!boost::filesystem::exists(dir / it->name))
            it = entries.erase(it);
        else
            ++it;
}
BOOL CTransientIndexedFile::WriteNew(STransientIndexedPointer* psPointer, void* pvData)
{
	CTransientIndexedFileDescriptor*	pcFile;
	filePos								iIndex;

	pcFile = GetOrCreateFile(psPointer->sIndexedMemory.uiSize);

	iIndex = pcFile->Write(pvData);
	if (iIndex == -1)
	{
		return FALSE;
	}

	psPointer->iFileIndex = pcFile->miFileIndex;
	psPointer->iIndexInFile = iIndex;
	return TRUE;

}