Esempio n. 1
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);
            }
        }
Esempio n. 2
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;
 }
Esempio n. 3
0
        public int UpdateSize()
        {
            int size = this.m_size;

            this.m_size = this.CalculateSize(ItemSizes.SizeOf(base.Item));
            return(this.m_size - size);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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;
     }
 }
        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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
        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;
        }
Esempio n. 16
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);
        }
        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);
        }
 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();
     }
 }
        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);
        }
Esempio n. 20
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);
        }
Esempio n. 21
0
 public override IReference <T> AllocateAndPin <T>(T obj, int priority)
 {
     return(this.InternalAllocate(obj, priority, true, ItemSizes.SizeOf((IStorable)(object)obj)));
 }
Esempio n. 22
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);
        }
Esempio n. 23
0
 public static int SizeOfInObjectArray(object obj)
 {
     return(ItemSizes.SizeOf(obj) - ItemSizes.ReferenceSize);
 }
Esempio n. 24
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);
        }
 public sealed override IReference <T> AllocateAndPin <T>(T obj, int priority)
 {
     return((IReference <T>) this.AllocateAndPin((IStorable)(object)obj, ItemSizes.SizeOf((IStorable)(object)obj)));
 }
Esempio n. 26
0
 public static int SizeOf <T>(ScalableList <T> obj)
 {
     return(ItemSizes.SizeOf((IStorable)obj));
 }