internal VirtualStream(VirtualStreamContainer stream, long stream_offset, long offset, long length) { m_stream = stream; m_offset = offset; m_length = length; m_stream_offset = stream_offset; m_stream.Container.Stream.Position = m_offset - m_stream_offset; }
/// <summary> /// Create a VirtualStream /// </summary> /// <param name="offset">absolute offset</param> /// <param name="length">length of virtual stream</param> /// <returns>VirtualStream instance</returns> public VirtualStream CreateStream(long offset, long length) { var range = new Range <Int64> { Minimum = offset, Maximum = offset + length }; //look for views in that size var stream = GetStreamByRange(range); if (stream != null) { Statistics.NumberOfStreamReuse++; //if found, create MappedViewContainer var mappedStreamContainer = new VirtualStreamContainer { Container = stream, Range = range }; mappedStreamContainer.MappedStream = new VirtualStream(mappedStreamContainer, stream.Range.Minimum, offset, length); stream.MappedStreams.Add(mappedStreamContainer); //ClearUnusedMappings(); return(mappedStreamContainer.MappedStream); } //if not found, create view, create MappedViewContainer var maximized = GetMaximizedRange(offset, length); var container = new MemoryMappedStreamContainer(); container.Range = maximized; container.MemoryMapper = this; //container.Stream = m_mmf.CreateViewStream(maximized.Minimum, maximized.Maximum - maximized.Minimum, MemoryMappedFileAccess.ReadWrite); m_streams.Add(container); Statistics.NumberOfStreamCreates++; //recursively get view (no reason to implement logic twice, only for optimizations) return(CreateStream(offset, length)); }
public new void Dispose() { //remove this stream from its container. m_stream.Container.MappedStreams.Remove(m_stream); m_stream = null; }