Ejemplo n.º 1
0
        internal BlobReader GetBlobReader(BlobHandle handle)
        {
            if (handle.IsVirtual)
            {
                if (_lazyVirtualHeapBlobs == null)
                {
                    Interlocked.CompareExchange(ref _lazyVirtualHeapBlobs, new VirtualHeapBlobTable(), null);
                }

                int index  = (int)handle.GetVirtualIndex();
                int length = s_virtualHeapBlobs[index].Length;

                VirtualHeapBlob virtualBlob;
                lock (_lazyVirtualHeapBlobs)
                {
                    if (!_lazyVirtualHeapBlobs.Table.TryGetValue(handle, out virtualBlob))
                    {
                        virtualBlob = new VirtualHeapBlob(GetVirtualBlobArray(handle, unique: false));
                        _lazyVirtualHeapBlobs.Table.Add(handle, virtualBlob);
                    }
                }

                return(new BlobReader(new MemoryBlock((byte *)virtualBlob.Pinned.AddrOfPinnedObject(), length)));
            }

            int offset, size;

            Block.PeekHeapValueOffsetAndSize(handle.Index, out offset, out size);
            return(new BlobReader(this.Block.GetMemoryBlockAt(offset, size)));
        }
Ejemplo n.º 2
0
        internal MemoryBlock GetMemoryBlock(BlobHandle handle)
        {
            if (handle.IsVirtual)
            {
                return(GetVirtualHandleMemoryBlock(handle));
            }

            int offset, size;

            Block.PeekHeapValueOffsetAndSize(handle.GetHeapOffset(), out offset, out size);
            return(Block.GetMemoryBlockAt(offset, size));
        }
Ejemplo n.º 3
0
        internal string GetString(UserStringHandle handle)
        {
            int offset, size;
            if (!Block.PeekHeapValueOffsetAndSize(handle.GetHeapOffset(), out offset, out size))
            {
                return string.Empty;
            }

            // Spec: Furthermore, there is an additional terminal byte (so all byte counts are odd, not even). 
            // The size in the blob header is the length of the string in bytes + 1.
            return Block.PeekUtf16(offset, size & ~1);
        }