void ProcessLeafs() { FileStream ThreadFilePtr = new FileStream(Filename, FileMode.Open, FileAccess.Read); FileBlock ThreadFileBlock = FileParts[Convert.ToInt16(Thread.CurrentThread.Name)]; Tiger TG = new Tiger(); byte[] DataBlock; byte[] Data = new byte[LeafSize + 1]; int LeafIndex, BlockLeafs; int i; ThreadFilePtr.Position = ThreadFileBlock.Start; while (ThreadFilePtr.Position < ThreadFileBlock.End) { LeafIndex = (int)ThreadFilePtr.Position / 1024; if (ThreadFileBlock.End - ThreadFilePtr.Position < DataBlockSize) { DataBlock = new byte[ThreadFileBlock.End - ThreadFilePtr.Position]; } else { DataBlock = new byte[DataBlockSize]; } ThreadFilePtr.Read(DataBlock, 0, DataBlock.Length); //read block BlockLeafs = DataBlock.Length / 1024; for (i = 0; i < BlockLeafs; i++) { Buffer.BlockCopy(DataBlock, i * LeafSize, Data, 1, LeafSize); TG.Initialize(); TTH[0][LeafIndex++] = TG.ComputeHash(Data); } if (i * LeafSize < DataBlock.Length) { Data = new byte[DataBlock.Length - BlockLeafs * LeafSize + 1]; Data[0] = LeafHash; Buffer.BlockCopy(DataBlock, BlockLeafs * LeafSize, Data, 1, (Data.Length - 1)); TG.Initialize(); TTH[0][LeafIndex++] = TG.ComputeHash(Data); Data = new byte[LeafSize + 1]; Data[0] = LeafHash; } } DataBlock = null; Data = null; }
void SplitFile() { long LeafsInPart = LeafCount / ThreadCount; // check if file is bigger then 1 MB or don't use threads if (FilePtr.Length > 1024 * 1024) { for (int i = 0; i < ThreadCount; i++) { FileParts[i] = new FileBlock(LeafsInPart * LeafSize * i, LeafsInPart * LeafSize * (i + 1)); } } FileParts[ThreadCount - 1].End = FilePtr.Length; }
void SplitFile() { long LeafsInPart = LeafCount / ThreadCount; // check if file is bigger then 1 MB or don't use threads if (FilePtr.Length > 1024 * 1024) for (int i = 0; i < ThreadCount; i++) FileParts[i] = new FileBlock(LeafsInPart * LeafSize * i, LeafsInPart * LeafSize * (i + 1)); FileParts[ThreadCount - 1].End = FilePtr.Length; }