private int AddNewBlob() { int newBlobIndex = _blobFiles.Length; var newBlobFiles = new FileStream[_blobFiles.Length + 1]; _blobFiles.CopyTo(newBlobFiles, 0); var newFreeSpace = new IntRangeList[_freeSpace.Length + 1]; _freeSpace.CopyTo(newFreeSpace, 0); var newBlobFileStreamPositions = new Stack <long> [_blobFileStreamPositions.Length + 1]; _blobFileStreamPositions.CopyTo(newBlobFileStreamPositions, 0); newBlobFiles[newBlobIndex] = File.Open(Path.Combine(_path, "blob" + newBlobIndex), FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None); newFreeSpace[newBlobIndex] = new IntRangeList(); newBlobFileStreamPositions[newBlobIndex] = new Stack <long>(); newBlobFiles[newBlobIndex].Write(new byte[HeaderLength], 0, HeaderLength); _blobFiles = newBlobFiles; _freeSpace = newFreeSpace; _blobFileStreamPositions = newBlobFileStreamPositions; return(newBlobIndex); }
internal void MarkFreeSpace <T>(T header) where T : BlockStructure { OnMarkingFreeSpace(); _blockStructureCache.Clear(); if (header is IHeader == false) { throw new ArgumentException(header.GetType() + " doesn't implement IHeader", "header"); } #if DebugVerboseSpace PrintUsedSpace(); Console.WriteLine("MarkFreeSpace called."); #endif for (int i = 0; i < _freeSpace.Length; i++) { _freeSpace[i] = new IntRangeList(); _freeSpace[i] += new Tuple <int, int>(HeaderLength, (int)_blobFiles[i].Length); } foreach (var kv in header.RecursiveUsedSpace) { _freeSpace[kv.Key] -= kv.Value; } #if DebugVerboseSpace PrintUsedSpace(); #endif }
private void PrintUsedSpace() { for (int b = 0; b < _blobFiles.Length; b++) { Console.Write("Blob {0}: ", b); IntRangeList fs = _freeSpace[b]; long max = _blobFiles[b].Length; int used = 0; #if DebugDrawUsedSpace for (int i = 0; i < max; i++) { if (Console.CursorLeft >= 100) { Console.WriteLine(); } if (fs.Contains(i)) { Console.Write("_"); } else { Console.Write("#"); used++; } } Console.WriteLine(); #else for (int i = 0; i < max; i++) { if (!fs.Contains(i)) { used++; } } #endif Console.WriteLine("Used ratio: {0}", (float)used / max); } }