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++; }