public StringDB5_0_0LowlevelDatabaseIODevice ( [NotNull] Stream stream, Func <BinaryReader, int, byte[]> buffer, bool leaveStreamOpen = false ) { _buffer = buffer; _stream = new StreamCacheMonitor(stream); _br = new BinaryReader(_stream, Encoding.UTF8, leaveStreamOpen); _bw = new BinaryWriter(_stream, Encoding.UTF8, leaveStreamOpen); if (_stream.Length < 8) { _bw.Write(0L); Seek(0); } JumpPos = _br.ReadInt64(); // we have to inc/dec jumppos since we write the index if (JumpPos > 0) { JumpPos--; } }
public StringDB10_0_0LowlevelDatabaseIODevice ( [NotNull] Stream stream, bool leaveStreamOpen = false ) { // We wrap the stream in this so that lookups to Position and Length are quick and snappy. // This is to prevent a performance concern regarding EOF using excessive amounts of time. // This has the issue of being cached, but calling IODevice.Reset should fix it right up. // Of course, this has bad implications and might be reverted later, but it definitely // fixes the performance gap without making the code ugly. _stream = new StreamCacheMonitor(stream); _br = new BinaryReader(_stream, Encoding.UTF8, leaveStreamOpen); _bw = new BinaryWriter(_stream, Encoding.UTF8, leaveStreamOpen); JumpPos = ReadBeginning(); }
public StringDB10_0_0LowlevelDatabaseIODevice ( [NotNull] Stream stream, bool leaveStreamOpen = false ) { // use a buffer when performing single byte writes since writing a single byte // allocates a new byte array every time, and that's a very costly operation. // the size of this buffer is artificial. // We wrap the stream in this so that lookups to Position and Length are quick and snappy. // This is to prevent a performance concern regarding EOF using excessive amounts of time. // This has the issue of being cached, but calling IODevice.Reset should fix it right up. // Of course, this has bad implications and might be reverted later, but it definitely // fixes the performance gap without making the code ugly. StreamCacheMonitor = new StreamCacheMonitor(stream); _br = new BinaryReader(StreamCacheMonitor, Encoding.UTF8, leaveStreamOpen); _bw = new BinaryWriter(StreamCacheMonitor, Encoding.UTF8, leaveStreamOpen); JumpPos = ReadBeginning(); }
public void Flush() { _bw.Flush(); StreamCacheMonitor.Flush(); }
public void Reset() { StreamCacheMonitor.UpdateCache(); Seek(sizeof(long)); }