コード例 #1
0
        private IDisposable SetAndPin(int index, T item, bool fromAdd)
        {
            this.CheckIndex(index, this.m_count - 1);
            IDisposable result;

            if (this.m_array != null)
            {
                result = this.m_array.PinValue();
                this.m_array.Value().Array[index] = item;
                if (fromAdd)
                {
                    this.m_array.UpdateSize(ItemSizes.SizeOfInObjectArray(item));
                }
            }
            else
            {
                int bucketIndex = this.GetBucketIndex(index);
                IReference <StorableArray> reference          = this.m_buckets[bucketIndex];
                UnPinCascadeHolder         unPinCascadeHolder = new UnPinCascadeHolder();
                unPinCascadeHolder.AddCleanupRef(reference.PinValue());
                this.m_buckets.PinContainingBucket(bucketIndex, unPinCascadeHolder);
                result = unPinCascadeHolder;
                StorableArray storableArray = reference.Value();
                storableArray.Array[this.GetIndexInBucket(index)] = item;
                if (fromAdd)
                {
                    reference.UpdateSize(ItemSizes.SizeOfInObjectArray(item));
                }
            }
            return(result);
        }
コード例 #2
0
        private void CacheItem(BaseReference reference, StorageItem item, bool fromDeserialize)
        {
            reference.Item = item;
            item.AddReference(reference);
            int num = ItemSizes.SizeOf(item);

            base.FreeCacheSpace(num, base.m_cacheSizeBytes);
            if (fromDeserialize)
            {
                this.CacheSetValue(reference.Id, item);
            }
            else
            {
                base.m_totalAuditedBytes += num;
            }
            base.m_cacheSizeBytes += num;
            this.EnqueueItem(item);
            object           item2           = item.Item;
            ISelfReferential selfReferential = item2 as ISelfReferential;

            if (selfReferential != null)
            {
                selfReferential.SetReference(reference);
            }
        }
コード例 #3
0
 public override void Free(BaseReference reference)
 {
     if (!(reference == (object)null))
     {
         ReferenceID id          = reference.Id;
         StorageItem storageItem = default(StorageItem);
         if (this.CacheTryGetValue(id, out storageItem))
         {
             this.CacheRemoveValue(id);
         }
         if (storageItem == null)
         {
             storageItem = (StorageItem)reference.Item;
         }
         if (storageItem != null)
         {
             if (storageItem.InQueue == InQueueState.InQueue)
             {
                 this.m_cachePriority.Remove(storageItem);
             }
             int num = ItemSizes.SizeOf(storageItem);
             base.m_cacheSizeBytes    -= num;
             base.m_totalAuditedBytes -= num;
             base.m_totalFreedBytes   += num;
             base.UpdatePeakCacheSize();
             storageItem.Item = null;
             storageItem.UnlinkReferences(false);
         }
         reference.Item = null;
     }
 }
コード例 #4
0
 private void SetValue(int index, T value, bool fromAdd)
 {
     this.CheckIndex(index, this.m_count - 1);
     if (this.m_array != null)
     {
         using (this.m_array.PinValue())
         {
             this.m_array.Value().Array[index] = value;
             if (fromAdd)
             {
                 this.m_array.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
             }
         }
     }
     else
     {
         IReference <StorableArray> reference = this.m_buckets[this.GetBucketIndex(index)];
         using (reference.PinValue())
         {
             StorableArray storableArray = reference.Value();
             storableArray.Array[this.GetIndexInBucket(index)] = value;
             if (fromAdd)
             {
                 reference.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
             }
         }
     }
     this.m_version++;
 }
コード例 #5
0
 protected override void FulfillInProgressFree()
 {
     base.m_storage.FreezeAllocations = true;
     while (base.m_inProgressFreeBytes > 0 && this.m_cachePriority.Count > 0)
     {
         StorageItem storageItem = this.m_cachePriority.ExtractLRU();
         storageItem.InQueue = InQueueState.None;
         if (storageItem.Item != null && storageItem.PinCount == 0)
         {
             this.CacheRemoveValue(storageItem.Id);
             int num = ItemSizes.SizeOf(storageItem);
             storageItem.Flush(base.m_storage, this.m_offsetMap);
             base.m_cacheSizeBytes -= num;
             if (base.m_cacheSizeBytes < 0)
             {
                 base.m_cacheSizeBytes = 0L;
             }
             base.m_inProgressFreeBytes -= num;
             if (base.m_inProgressFreeBytes < 0)
             {
                 base.m_inProgressFreeBytes = 0L;
             }
         }
     }
     base.m_storage.FreezeAllocations = false;
 }
コード例 #6
0
        public int UpdateSize()
        {
            int size = this.m_size;

            this.m_size = this.CalculateSize(ItemSizes.SizeOf(base.Item));
            return(this.m_size - size);
        }
コード例 #7
0
        public static int SizeOf(Hashtable obj)
        {
            int referenceSize = ItemSizes.ReferenceSize;

            if (obj != null)
            {
                referenceSize += 56;
                IDictionaryEnumerator enumerator = obj.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator.Current;
                        referenceSize += 4;
                        referenceSize += ItemSizes.SizeOf(dictionaryEntry.Key);
                        referenceSize += ItemSizes.SizeOf(dictionaryEntry.Value);
                    }
                    return(referenceSize);
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            return(referenceSize);
        }
        public void SetTreePartitionContentsAndPin <T>(IReference <T> emptyPartitionRef, T contents) where T : IStorable
        {
            BaseReference baseReference = (BaseReference)emptyPartitionRef;

            this.m_partitionManager.TreeHasChanged = true;
            this.CacheItem(baseReference, (IStorable)(object)contents, false, ItemSizes.SizeOf((IStorable)(object)contents));
            baseReference.PinValue();
            this.CacheSetValue(baseReference.Id, baseReference);
        }
コード例 #9
0
        public static int SizeOf(Array arr)
        {
            int num = ItemSizes.ReferenceSize;

            if (arr != null)
            {
                num += 8;
                int[] indices = new int[arr.Rank];
                num += ItemSizes.TraverseArrayDim(arr, 0, indices);
            }
            return(num);
        }
コード例 #10
0
        private static int TraverseArrayDim(Array arr, int dim, int[] indices)
        {
            int  num    = 0;
            bool flag   = arr.Rank == dim + 1;
            int  length = arr.GetLength(dim);

            for (int i = 0; i < length; i++)
            {
                indices[dim] = i;
                num          = ((!flag) ? (num + ItemSizes.TraverseArrayDim(arr, dim + 1, indices)) : (num + ItemSizes.SizeOf(arr.GetValue(indices))));
            }
            return(num);
        }
コード例 #11
0
        public static int SizeOf <T>(List <T> list) where T : IStorable
        {
            int num = ItemSizes.ReferenceSize;

            if (list != null)
            {
                num += 24;
                for (int i = 0; i < list.Count; i++)
                {
                    num += ItemSizes.SizeOf((IStorable)(object)list[i]);
                }
            }
            return(num);
        }
コード例 #12
0
        public static int SizeOf(IList obj)
        {
            int num = ItemSizes.ReferenceSize;

            if (obj != null)
            {
                num += 24;
                for (int i = 0; i < obj.Count; i++)
                {
                    num += ItemSizes.SizeOf(obj[i]);
                }
            }
            return(num);
        }
コード例 #13
0
        public static int SizeOf(List <object> list)
        {
            int num = ItemSizes.ReferenceSize;

            if (list != null)
            {
                num += 24;
                for (int i = 0; i < list.Count; i++)
                {
                    num += ItemSizes.SizeOf(list[i]);
                }
            }
            return(num);
        }
コード例 #14
0
        public static int SizeOf(List <object>[] obj)
        {
            int num = ItemSizes.ReferenceSize;

            if (obj != null)
            {
                num += 8;
                for (int i = 0; i < obj.Length; i++)
                {
                    num += ItemSizes.SizeOf(obj[i]);
                }
            }
            return(num);
        }
コード例 #15
0
        public static int SizeOf(object[] array)
        {
            int num = ItemSizes.ReferenceSize;

            if (array != null)
            {
                num += 8;
                for (int i = 0; i < array.Length; i++)
                {
                    num += ItemSizes.SizeOf(array[i]);
                }
            }
            return(num);
        }
コード例 #16
0
        public static int SizeOf <T>(T[] array) where T : IStorable
        {
            int num = ItemSizes.ReferenceSize;

            if (array != null)
            {
                num += 8;
                for (int i = 0; i < array.Length; i++)
                {
                    num += ItemSizes.SizeOf((IStorable)(object)array[i]);
                }
            }
            return(num);
        }
コード例 #17
0
        public static int SizeOf <T>(List <T[]> obj) where T : IStorable
        {
            int num = ItemSizes.ReferenceSize;

            if (obj != null)
            {
                num += 24;
                for (int i = 0; i < obj.Count; i++)
                {
                    num += ItemSizes.SizeOf(obj[i]);
                }
            }
            return(num);
        }
コード例 #18
0
        public static int SizeOf <T>(List <List <T> > listOfLists) where T : IStorable
        {
            int num = ItemSizes.ReferenceSize;

            if (listOfLists != null)
            {
                num += 24;
                for (int i = 0; i < listOfLists.Count; i++)
                {
                    num += ItemSizes.SizeOf(listOfLists[i]);
                }
            }
            return(num);
        }
コード例 #19
0
        private void UpdateStatsForRemovedItem(BaseReference itemRef, ref long bytesToFree)
        {
            long num  = ItemSizes.SizeOf(itemRef.Item.Item);
            long num2 = base.m_cacheSizeBytes - num;
            long num3 = this.m_cacheFreeableBytes - num;

            if (num3 < 0)
            {
                num3 = 0L;
            }
            if (num2 < num3)
            {
                num2 = num3;
            }
            this.m_cacheFreeableBytes = num3;
            base.m_cacheSizeBytes     = num2;
            bytesToFree -= num;
        }
コード例 #20
0
        public static int SizeOf <K, V>(Dictionary <K, V> obj)
        {
            int referenceSize = ItemSizes.ReferenceSize;

            if (obj != null)
            {
                referenceSize += 56;
                {
                    foreach (KeyValuePair <K, V> item in obj)
                    {
                        referenceSize += 4;
                        referenceSize += ItemSizes.SizeOf(item.Key);
                        referenceSize += ItemSizes.SizeOf(item.Value);
                    }
                    return(referenceSize);
                }
            }
            return(referenceSize);
        }
コード例 #21
0
        private IStorable LoadItem(BaseReference reference)
        {
            if (base.m_inStreamOper)
            {
                Global.Tracer.Assert(false, "PartitionedTreeScalabilityCache should not Load during serialization");
            }
            IStorable storable = null;

            try
            {
                base.m_inStreamOper = true;
                base.m_deserializationTimer.Start();
                ReferenceID id = reference.Id;
                long        num;
                if (!id.IsTemporary && id.HasMultiPart)
                {
                    num = this.m_partitionManager.GetTreePartitionOffset(id);
                    if (num < 0)
                    {
                        return(null);
                    }
                }
                else
                {
                    num = reference.Id.Value;
                }
                if (num < 0)
                {
                    Global.Tracer.Assert(false, "Invalid offset for item.  ReferenceID: {0}, Offset: {1}", id, num);
                }
                long num2 = default(long);
                storable = (IStorable)base.m_storage.Retrieve(num, out num2);
            }
            finally
            {
                base.m_inStreamOper = false;
                base.m_deserializationTimer.Stop();
            }
            this.CacheItem(reference, storable, true, ItemSizes.SizeOf(storable));
            return(storable);
        }
コード例 #22
0
 public sealed override void UnPin(BaseReference reference)
 {
     if (reference.PinCount == 0 && (reference.Id.IsTemporary || reference.Id.HasMultiPart) && reference.InQueue == InQueueState.None)
     {
         reference.InQueue = InQueueState.InQueue;
         this.m_serializationQueue.Enqueue(reference);
         if (!this.m_lockedDownForFlush)
         {
             ItemHolder item = reference.Item;
             IStorable  obj  = null;
             if (item != null)
             {
                 obj = item.Item;
             }
             this.m_cacheFreeableBytes += ItemSizes.SizeOf(obj);
         }
     }
     if (!this.m_lockedDownForFlush)
     {
         base.PeriodicOperationCheck();
     }
 }
コード例 #23
0
        public sealed override IStorable Retrieve(BaseReference reference)
        {
            if (reference.Item == null)
            {
                ReferenceID   id            = reference.Id;
                BaseReference baseReference = default(BaseReference);
                if (this.CacheTryGetValue(id, out baseReference) && baseReference.Item != null)
                {
                    IStorable item = baseReference.Item.Item;
                    this.CacheItem(reference, item, true, ItemSizes.SizeOf(item));
                }
                else
                {
                    this.LoadItem(reference);
                }
            }
            IStorable result = null;

            if (reference.Item != null)
            {
                result = reference.Item.Item;
            }
            return(result);
        }
コード例 #24
0
        public override IReference <T> GenerateFixedReference <T>(T obj)
        {
            BaseReference baseReference = base.CreateReference((IStorable)(object)obj);

            baseReference.Init(this, this.m_offsetMap.GenerateTempId());
            StorageItem storageItem = (StorageItem)(baseReference.Item = new StorageItem(baseReference.Id, -1, (IStorable)(object)obj, ItemSizes.SizeOf((IStorable)(object)obj)));

            storageItem.AddReference(baseReference);
            storageItem.InQueue         = InQueueState.Exempt;
            storageItem.HasBeenUnPinned = true;
            ISelfReferential selfReferential = ((object)obj) as ISelfReferential;

            if (selfReferential != null)
            {
                selfReferential.SetReference(baseReference);
            }
            return((IReference <T>)baseReference);
        }
コード例 #25
0
 public static int SizeOfInObjectArray(object obj)
 {
     return(ItemSizes.SizeOf(obj) - ItemSizes.ReferenceSize);
 }
コード例 #26
0
 public override IReference <T> AllocateAndPin <T>(T obj, int priority)
 {
     return(this.InternalAllocate(obj, priority, true, ItemSizes.SizeOf((IStorable)(object)obj)));
 }
コード例 #27
0
        public static int SizeOf(object obj)
        {
            if (obj == null)
            {
                return(ItemSizes.ReferenceSize);
            }
            if (obj is IStorable)
            {
                return(ItemSizes.SizeOf((IStorable)obj));
            }
            if (obj is IConvertible)
            {
                switch (((IConvertible)obj).GetTypeCode())
                {
                case TypeCode.Boolean:
                case TypeCode.Char:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Single:
                    return(ItemSizes.ReferenceSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);

                case TypeCode.Int64:
                case TypeCode.UInt64:
                case TypeCode.Double:
                    return(8 + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);

                case TypeCode.String:
                    return(ItemSizes.SizeOf((string)obj));

                case TypeCode.Decimal:
                    return(16 + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);

                case TypeCode.DateTime:
                    return(8 + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);

                case TypeCode.Object:
                    if (obj is TimeSpan)
                    {
                        return(8 + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is DateTimeOffset)
                    {
                        return(16 + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is Guid)
                    {
                        return(16 + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is Color)
                    {
                        return(ItemSizes.GdiColorSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    return(ItemSizes.ReferenceSize);
                }
            }
            else
            {
                if (obj is Array)
                {
                    return(ItemSizes.SizeOf((Array)obj));
                }
                if (obj is IList)
                {
                    return(ItemSizes.SizeOf((IList)obj));
                }
                if (Nullable.GetUnderlyingType(obj.GetType()) != null)
                {
                    if (obj is bool?)
                    {
                        return(ItemSizes.NullableBoolSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is byte?)
                    {
                        return(ItemSizes.NullableByteSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is sbyte?)
                    {
                        return(ItemSizes.NullableByteSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is short?)
                    {
                        return(ItemSizes.NullableInt16Size + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is int?)
                    {
                        return(ItemSizes.NullableInt32Size + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is long?)
                    {
                        return(ItemSizes.NullableInt64Size + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is ushort?)
                    {
                        return(ItemSizes.NullableInt16Size + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is uint?)
                    {
                        return(ItemSizes.NullableInt32Size + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is ulong?)
                    {
                        return(ItemSizes.NullableInt64Size + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is char?)
                    {
                        return(ItemSizes.NullableCharSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is double?)
                    {
                        return(ItemSizes.NullableDoubleSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is float?)
                    {
                        return(ItemSizes.NullableSingleSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is DateTime?)
                    {
                        return(ItemSizes.NullableDateTimeSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is Guid?)
                    {
                        return(ItemSizes.NullableGuidSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                    if (obj is TimeSpan?)
                    {
                        return(ItemSizes.NullableTimeSpanSize + ItemSizes.ObjectOverhead + ItemSizes.ReferenceSize);
                    }
                }
            }
            return(ItemSizes.ReferenceSize);
        }
コード例 #28
0
        private bool Insert(ScalableDictionaryNodeReference nodeRef, int hashCode, TKey key, TValue value, bool add, int level, bool updateSize, out IDisposable cleanupRef)
        {
            IDisposable            disposable             = nodeRef.PinValue();
            ScalableDictionaryNode scalableDictionaryNode = nodeRef.Value();
            bool flag = false;
            int  num  = this.HashToSlot(scalableDictionaryNode, hashCode, level);
            IScalableDictionaryEntry scalableDictionaryEntry = scalableDictionaryNode.Entries[num];

            if (scalableDictionaryEntry == null)
            {
                ScalableDictionaryValues scalableDictionaryValues = new ScalableDictionaryValues(this.m_valuesCapacity);
                scalableDictionaryValues.Keys[0]   = key;
                scalableDictionaryValues.Values[0] = value;
                scalableDictionaryValues.Count++;
                scalableDictionaryNode.Entries[num] = scalableDictionaryValues;
                flag       = true;
                cleanupRef = disposable;
                if (!this.m_useFixedReferences && updateSize)
                {
                    int sizeBytesDelta = ItemSizes.SizeOfInObjectArray(key) + ItemSizes.SizeOfInObjectArray(value) + scalableDictionaryValues.EmptySize;
                    nodeRef.UpdateSize(sizeBytesDelta);
                }
            }
            else
            {
                switch (scalableDictionaryEntry.GetObjectType())
                {
                case AspNetCore.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryNodeReference:
                {
                    ScalableDictionaryNodeReference nodeRef2 = scalableDictionaryEntry as ScalableDictionaryNodeReference;
                    flag = this.Insert(nodeRef2, hashCode, key, value, add, level + 1, updateSize, out cleanupRef);
                    break;
                }

                case AspNetCore.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryValues:
                {
                    ScalableDictionaryValues scalableDictionaryValues2 = scalableDictionaryEntry as ScalableDictionaryValues;
                    bool flag2 = false;
                    cleanupRef = null;
                    int num2 = 0;
                    while (num2 < scalableDictionaryValues2.Count)
                    {
                        if (!this.m_comparer.Equals(key, (TKey)scalableDictionaryValues2.Keys[num2]))
                        {
                            num2++;
                            continue;
                        }
                        if (add)
                        {
                            Global.Tracer.Assert(false, "ScalableDictionary: An element with the same key already exists within the Dictionary");
                        }
                        scalableDictionaryValues2.Values[num2] = value;
                        flag2      = true;
                        flag       = false;
                        cleanupRef = disposable;
                        break;
                    }
                    if (!flag2)
                    {
                        if (scalableDictionaryValues2.Count < scalableDictionaryValues2.Capacity)
                        {
                            int count = scalableDictionaryValues2.Count;
                            scalableDictionaryValues2.Keys[count]   = key;
                            scalableDictionaryValues2.Values[count] = value;
                            scalableDictionaryValues2.Count++;
                            flag       = true;
                            cleanupRef = disposable;
                            if (!this.m_useFixedReferences && updateSize)
                            {
                                nodeRef.UpdateSize(ItemSizes.SizeOfInObjectArray(key));
                                nodeRef.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
                            }
                        }
                        else
                        {
                            ScalableDictionaryNodeReference scalableDictionaryNodeReference = this.BuildNode(level + 1, this.m_nodeCapacity);
                            scalableDictionaryNode.Entries[num] = scalableDictionaryNodeReference;
                            using (scalableDictionaryNodeReference.PinValue())
                            {
                                if (!this.m_useFixedReferences && updateSize)
                                {
                                    int num3 = ItemSizes.SizeOfInObjectArray(scalableDictionaryValues2);
                                    nodeRef.UpdateSize(num3 * -1);
                                    scalableDictionaryNodeReference.UpdateSize(num3);
                                }
                                for (int i = 0; i < scalableDictionaryValues2.Count; i++)
                                {
                                    TKey        key2        = (TKey)scalableDictionaryValues2.Keys[i];
                                    IDisposable disposable2 = default(IDisposable);
                                    this.Insert(scalableDictionaryNodeReference, this.GetHashCode(key2), key2, (TValue)scalableDictionaryValues2.Values[i], false, level + 1, false, out disposable2);
                                    disposable2.Dispose();
                                }
                                flag = this.Insert(scalableDictionaryNodeReference, hashCode, key, value, add, level + 1, updateSize, out cleanupRef);
                            }
                        }
                    }
                    break;
                }

                default:
                    Global.Tracer.Assert(false, "Unknown ObjectType");
                    cleanupRef = null;
                    break;
                }
            }
            if (flag)
            {
                scalableDictionaryNode.Count++;
            }
            if (disposable != cleanupRef)
            {
                disposable.Dispose();
            }
            return(flag);
        }
コード例 #29
0
 public sealed override IReference <T> AllocateAndPin <T>(T obj, int priority)
 {
     return((IReference <T>) this.AllocateAndPin((IStorable)(object)obj, ItemSizes.SizeOf((IStorable)(object)obj)));
 }
コード例 #30
0
 public static int SizeOf <T>(ScalableList <T> obj)
 {
     return(ItemSizes.SizeOf((IStorable)obj));
 }