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

AllocateSpace() public method

Allocates size byte(s) of unused space at the end of the stream.
public AllocateSpace ( uint size ) : long?
size uint The number of bytes to allocate.
return long?
        public unsafe long? AllocateSpace(uint size)
        {
            if (size == 0)
                return null;

            long oldSize, newSize;
            // This is thread-safe, but because we bump the DataLength without
            //  making any effort to ensure the data in the region is valid,
            //  other threads may attempt to read it and find random garbage
            //  there.
            // On the bright side, MSDN claims that unused regions in a mapped
            //  file are always zeroes, and this seems to be true so far. Given
            //  this, most of the time you just need a 'this data is valid' bit
            //  tucked away to protect yourself from reading uninitialized data.
            using (var header = AccessHeader()) {
                newSize = Interlocked.Add(ref header.Ptr->DataLength, size);
                oldSize = newSize - size;
            }

            EnsureCapacity(newSize + HeaderSize);
            return oldSize;
        }

Usage Example

示例#1
0
        private long CreateNode()
        {
            long offset   = IndexStream.AllocateSpace(BTreeNode.TotalSize).Value;
            var  newIndex = (offset - BTreeHeader.Size) / BTreeNode.TotalSize;

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