public Heap(Stream stream, bool useCompression = false, AllocationStrategy strategy = AllocationStrategy.FromTheCurrentBlock) { stream.Seek(0, SeekOrigin.Begin); //support Seek? Stream = stream; space = new Space(); used = new Dictionary <long, Pointer>(); reserved = new Dictionary <long, Pointer>(); if (stream.Length < AtomicHeader.SIZE) //create new { header = new AtomicHeader(); header.UseCompression = useCompression; space.Add(new Ptr(AtomicHeader.SIZE, long.MaxValue - AtomicHeader.SIZE)); } else //open exist (ignore the useCompression flag) { header = AtomicHeader.Deserialize(Stream); stream.Seek(header.SystemData.Position, SeekOrigin.Begin); Deserialize(new BinaryReader(stream)); //manual alloc header.SystemData var ptr = space.Alloc(header.SystemData.Size); if (ptr.Position != header.SystemData.Position) { throw new Exception("Logical error."); } } Strategy = strategy; currentVersion++; }
public Heap(Stream system, Stream data, long initialFreeSize, bool useCompression) { system.Seek(0, SeekOrigin.Begin); //support Seek? data.Seek(0, SeekOrigin.Begin); //support Seek? System = system; Data = data; header = AtomicHeader.Deserialize(System); space = new Space(); used = new Dictionary <long, Pointer>(); reserved = new Dictionary <long, Pointer>(); if (header.LastFlush == Ptr.NULL) { space.Add(new Ptr(0, initialFreeSize)); } else { system.Seek(header.LastFlush.Position, SeekOrigin.Begin); Deserialize(new BinaryReader(system)); } UseCompression = useCompression; currentVersion++; }