Squared.Data.Mangler.Internal.StreamRef.AccessRange C# (CSharp) Method

AccessRange() public method

Accesses a range of bytes within the stream.
public AccessRange ( long offset, uint size, MemoryMappedFileAccess access = MemoryMappedFileAccess.ReadWrite ) : StreamRange
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 StreamRange
        public StreamRange AccessRange(long offset, uint size, MemoryMappedFileAccess access = MemoryMappedFileAccess.ReadWrite)
        {
            unchecked {
                long actualBegin = offset + HeaderSize;
                uint actualSize = size;

                EnsureCapacity(HeaderSize + offset + actualSize);

                var viewRef = Cache.CreateView(actualBegin, actualSize, access);

                return new StreamRange(
                    this, viewRef, actualBegin, actualSize
                );
            }
        }

Usage Example

Example #1
0
        public StreamRange AccessNode(long index, bool forWrite)
        {
            unchecked {
                long position = BTreeHeader.Size + (index * BTreeNode.TotalSize);
                var  range    = IndexStream.AccessRange(position, BTreeNode.TotalSize, MemoryMappedFileAccess.ReadWrite);

                var pNode = (BTreeNode *)range.Pointer;

                if (pNode->IsValid != 1)
                {
                    // If the node is fully uninitialized, locking it for write is okay
                    if ((pNode->NumValues != 0) || (pNode->HasLeaves != 0))
                    {
                        throw new InvalidDataException();
                    }
                }

                if (forWrite)
                {
                    pNode->IsValid = 0;
                }

                return(range);
            }
        }
All Usage Examples Of Squared.Data.Mangler.Internal.StreamRef::AccessRange