public AccessRangeUncached ( long offset, uint size, MemoryMappedFileAccess access = MemoryMappedFileAccess.ReadWrite ) : |
||
offset | long | The offset within the stream, relative to the end of the stream header. |
size | uint | The size of the range to access, in bytes. |
access | MemoryMappedFileAccess | |
return |
private void EnsureFreelistExists() { var pHeader = (BTreeHeader *)_HeaderRange.Pointer; if (EnableFreelist) { long oldOffset = 0; if (pHeader->FreelistIndexOffset == 0) { uint size = FreelistIndex.Size; long?offset = AllocateDataSpace(ref size); if (!offset.HasValue) { throw new OutOfMemoryException("Unable to allocate space for freelist index in data stream."); } oldOffset = Interlocked.Exchange(ref pHeader->FreelistIndexOffset, offset.Value); } _FreelistIndexRange = DataStream.AccessRangeUncached(pHeader->FreelistIndexOffset, FreelistIndex.Size, MemoryMappedFileAccess.ReadWrite); Native.memset(_FreelistIndexRange.Pointer, 0, new UIntPtr(FreelistIndex.Size / 4)); if (oldOffset != 0) { FreelistPut(oldOffset, FreelistIndex.Size); } } else { pHeader->FreelistIndexOffset = 0; } }
public BTree(StreamSource storage, string prefix) { Storage = storage; Prefix = prefix; IndexStream = Storage.Open(prefix + "index"); KeyStream = Storage.Open(prefix + "keys"); DataStream = Storage.Open(prefix + "data"); VersionCheck(IndexStream); VersionCheck(KeyStream); VersionCheck(DataStream); bool needInit = IndexStream.Length < BTreeHeader.Size; IndexStream.LengthChanging += IndexStream_LengthChanging; IndexStream.LengthChanged += IndexStream_LengthChanged; DataStream.LengthChanging += DataStream_LengthChanging; DataStream.LengthChanged += DataStream_LengthChanged; _GetKeyOfEntry = ReadKey; _HeaderRange = IndexStream.AccessRangeUncached(0, BTreeHeader.Size); if (needInit) { InitializeBTree(); } _FreelistBucketLocks = new object[FreelistIndex.BucketCount]; for (int i = 0; i < _FreelistBucketLocks.Length; i++) { _FreelistBucketLocks[i] = new object(); } EnsureFreelistExists(); }
void IndexStream_LengthChanged(object sender, EventArgs e) { _HeaderRange = IndexStream.AccessRangeUncached(0, BTreeHeader.Size); }