public unsafe void WriteBuffer(long position, byte *srcPointer, int sizeToWrite) { _locker.EnterWriteLock(); try { if (position != _lastPos) { throw new InvalidOperationException("Journal writes must be to the next location in the journal"); } _lastPos += sizeToWrite; var handle = Marshal.AllocHGlobal(sizeToWrite); var buffer = new Buffer { Handle = handle, Pointer = (byte *)handle.ToPointer(), SizeInPages = sizeToWrite / _options.PageSize }; _buffers = _buffers.Append(buffer); Memory.Copy(buffer.Pointer, (byte *)srcPointer, sizeToWrite); } finally { _locker.ExitWriteLock(); } }
public void WriteGather(long position, IntPtr[] pages) { _locker.EnterWriteLock(); try { if (position != _lastPos) { throw new InvalidOperationException("Journal writes must be to the next location in the journal"); } var size = pages.Length * AbstractPager.PageSize; _lastPos += size; var handle = Marshal.AllocHGlobal(size); var buffer = new Buffer { Handle = handle, Pointer = (byte *)handle.ToPointer(), SizeInPages = pages.Length }; _buffers = _buffers.Append(buffer); for (int index = 0; index < pages.Length; index++) { Memory.Copy(buffer.Pointer + (index * AbstractPager.PageSize), (byte *)pages[index].ToPointer(), AbstractPager.PageSize); } } finally { _locker.ExitWriteLock(); } }
private JournalFile NextFile(int numberOfPages = 1) { _journalIndex++; var now = DateTime.UtcNow; if ((now - _lastFile).TotalSeconds < 90) { _currentJournalFileSize = Math.Min(_env.Options.MaxLogFileSize, _currentJournalFileSize * 2); } var actualLogSize = _currentJournalFileSize; var minRequiredSize = numberOfPages * AbstractPager.PageSize; if (_currentJournalFileSize < minRequiredSize) { actualLogSize = minRequiredSize; } _lastFile = now; var journalPager = _env.Options.CreateJournalWriter(_journalIndex, actualLogSize); var journal = new JournalFile(journalPager, _journalIndex); journal.AddRef(); // one reference added by a creator - write ahead log _files = _files.Append(journal); _headerAccessor.Modify(_updateLogInfo); return(journal); }
public void WritePages(long position, byte *p, int numberOfPages) { _locker.EnterWriteLock(); try { if (position != _lastPos) { throw new InvalidOperationException("Journal writes must be to the next location in the journal"); } var size = numberOfPages * _options.PageSize; _lastPos += size; var handle = NativeMemory.AllocateMemory(size); var buffer = new Buffer { Pointer = handle, SizeInPages = numberOfPages }; _buffers = _buffers.Append(buffer); Memory.Copy(buffer.Pointer, p, numberOfPages * _options.PageSize); } finally { _locker.ExitWriteLock(); } }
public PureMemoryPager(byte[] data) { var ptr = Marshal.AllocHGlobal(data.Length); var buffer = new Buffer { Handle = ptr, Base = (byte *)ptr.ToPointer(), Size = data.Length }; _buffers = _buffers.Append(buffer); NumberOfAllocatedPages = data.Length / PageSize; PagerState.Release(); PagerState = new PagerState(this); PagerState.AddRef(); fixed(byte *origin = data) { NativeMethods.memcpy(buffer.Base, origin, data.Length); } }