memset() private method

private memset ( byte dest, int value, UIntPtr count ) : int
dest byte
value int
count System.UIntPtr
return int
Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        public StreamRange LockValue(long nodeIndex, uint valueIndex, long?minimumSize, out BTreeValue *pValue, out ushort keyType)
        {
            var result = AccessNode(nodeIndex, true);

            unchecked {
                pValue = (BTreeValue *)(result.Pointer + BTreeNode.OffsetOfValues + (valueIndex * BTreeValue.Size));

                keyType         = pValue->KeyType;
                pValue->KeyType = 0;
            }

            var lockLength = pValue->DataLength;

            if ((minimumSize.HasValue) && (minimumSize.Value > lockLength))
            {
                lockLength = (uint)minimumSize.Value;

                var oldPosition = pValue->DataOffset;
                var oldLength   = pValue->DataLength + pValue->ExtraDataBytes;

                pValue->DataOffset     = (uint)AllocateDataSpace(ref lockLength).Value;
                pValue->ExtraDataBytes = (uint)(lockLength - oldLength);

                using (var oldDataRange = DataStream.AccessRange(oldPosition, oldLength))
                    using (var dataRange = DataStream.AccessRange(pValue->DataOffset, pValue->DataLength)) {
                        Native.memmove(dataRange.Pointer, oldDataRange.Pointer, new UIntPtr(pValue->DataLength));
                        Native.memset(oldDataRange.Pointer, 0, new UIntPtr(pValue->DataLength));
                    }

                FreelistPut(oldPosition, oldLength);
            }

            return(result);
        }
Esempio n. 3
0
        public void Clear()
        {
            IndexStream.Clear();
            KeyStream.Clear();
            DataStream.Clear();

            Native.memset(_HeaderRange.Pointer, 0, new UIntPtr(BTreeHeader.Size));
            Native.memset(_FreelistIndexRange.Pointer, 0, new UIntPtr(FreelistIndex.Size));

            InitializeBTree();
        }
Esempio n. 4
0
 public static void ZeroBytes(byte *ptr, long offset, uint count)
 {
     Native.memset(ptr + offset, 0, new UIntPtr((uint)count));
 }