/// <summary> /// Verifica se existe espaço para aramzenar o item informado substituindo um /// item já existente. /// </summary> /// <param name="oldItem">Item já existente.</param> /// <param name="newItem">Novo item que será adicionado.</param> /// <returns></returns> protected StoreStatus HasSpace(ISizable oldItem, ISizable newItem) { long num = (_dataSize + newItem.Size) - ((oldItem == null) ? ((long)0) : ((long)oldItem.Size)); StoreStatus hasSpace = StoreStatus.HasSpace; try { if (SystemMemoryTask.PercentMemoryUsed <= 90) { if (num <= _maxSize) { return(hasSpace); } if (num > (_maxSize + _extraDataSize)) { return(StoreStatus.HasNotEnoughSpace); } return(StoreStatus.NearEviction); } if (_extraDataSize > 0) { return(StoreStatus.NearEviction); } return(StoreStatus.HasNotEnoughSpace); } catch (Exception) { } return(StoreStatus.HasNotEnoughSpace); }
/// <summary> /// Check if store has enough space to add new item /// </summary> /// <param name="oldItem">old item</param> /// <param name="newItem">new item to be inserted</param> /// <returns>true is store has space, else false</returns> protected StoreStatus HasSpace(ISizable oldItem, ISizable newItem, long keySize, Boolean allowExtendedSize) { if (VirtualUnlimitedSpace) { return(StoreStatus.HasSpace); } long maxSize = _maxSize; if (!allowExtendedSize) { maxSize = (long)(_maxSize * .95); } long nextSize = TotalDataSize + newItem.InMemorySize - (oldItem == null ? -keySize : oldItem.InMemorySize); StoreStatus status = StoreStatus.HasSpace; if (nextSize > maxSize) { if (nextSize > (maxSize + _extraDataSize)) { return(StoreStatus.HasNotEnoughSpace); } return(StoreStatus.NearEviction); } return(status); }
/// <summary> /// Verifica se existe espaço para armazenar o item informado. /// </summary> /// <param name="item">Item que será armazenado.</param> /// <returns></returns> protected StoreStatus HasSpace(ISizable item) { long num = _dataSize + item.Size; StoreStatus hasSpace = StoreStatus.HasSpace; if (SystemMemoryTask.PercentMemoryUsed > 90) { if (_extraDataSize > 0) { hasSpace = StoreStatus.NearEviction; } else { hasSpace = StoreStatus.HasNotEnoughSpace; } } if (num <= _maxSize) { return(hasSpace); } if (num > (_maxSize + _extraDataSize)) { return(StoreStatus.HasNotEnoughSpace); } return(StoreStatus.NearEviction); }
public AspectRatioKeeper(ISizable sizable) { Sizable = sizable; Sizable.WidthChanged += SizableOnWidthChanged; Sizable.HeightChanged += SizableOnHeightChanged; Aspect = Sizable.Width / Sizable.Height; }
/// <summary> /// Check if store has enough space to add new item /// </summary> /// <param name="item">item to be added</param> /// <returns>true is store has space, else false</returns> public virtual StoreStatus HasSpace(ISizable item, long keySize, Boolean allowExtendedSize) { // Keysize will be included in actual cachesize if (VirtualUnlimitedSpace) { return(StoreStatus.HasSpace); } long maxSize = _maxSize; if (!allowExtendedSize) { maxSize = (long)(_maxSize * .95); } long nextSize = TotalDataSize + item.InMemorySize + keySize; StoreStatus status = StoreStatus.HasSpace; if (nextSize > maxSize) { if (nextSize > (maxSize + _extraDataSize)) { status = StoreStatus.HasNotEnoughSpace; } else { status = StoreStatus.NearEviction; } } return(status); }
private static Size GetRelativeSize(ISizable child, Size parentSize) { var widthProportion = child.Width / parentSize.Width; var heightProportion = child.Height / parentSize.Height; return(new Size(widthProportion, heightProportion)); }
/// <summary> /// Get the position which would be required to center the specified sizable object to the specified Viewport. /// </summary> /// <param name="obj">The sizable object to center.</param> /// <param name="centerToViewport">The viewport to center the ISizable to.</param> /// <param name="origin">The origin of the ISizable, unscaled.</param> /// <returns>The position which would be required to center the specified sizable object.</returns> public static Vector2 GetCenterPosition(this ISizable obj, Viewport centerToViewport, Vector2 origin) { Vector2 centerOfViewport = new Vector2(centerToViewport.Width / 2, centerToViewport.Height / 2); centerOfViewport.X -= (obj.Width / 2f) - origin.X * (obj is IScaled ? (obj as IScaled).Scale.X : 1); centerOfViewport.Y -= (obj.Height / 2f) - origin.Y * (obj is IScaled ? (obj as IScaled).Scale.Y : 1); return(centerOfViewport); }
private void Initialize(int length) { if (!customLength) { Type genericType = typeof(T); T defaultOfType = default(T); try { ISizable reference = defaultOfType as ISizable; if (reference != null) { _sizeOfReference = reference.Size; } else if (genericType.IsValueType) { _sizeOfReference = System.Runtime.InteropServices.Marshal.SizeOf(defaultOfType); } else { _sizeOfReference = IntPtr.Size; } } catch { _sizeOfReference = SizeOfType(genericType); } _lengthThreshold = (81920 / _sizeOfReference); _length = length; int superLength = (length / _lengthThreshold) + 1; //Usman: //I still believe we need this exception, if we need to keep the main referencial array in SOH. //An array declared with greater supersize than length threshold will be declared in LOH. //The exception should be removed if we don't care that the main referencial array is being taken to LOH. //Otherwise it should be caught by user, who will then declare a new clustered array structure. //if (superLength < 0 || superLength > _lengthThreshold) // throw new ArgumentOutOfRangeException(length.ToString("length")); //Your call. //Update: Let it grow, care later. _chunks = new T[superLength][]; for (int i = 0; i < superLength; i++) { _chunks[i] = new T[length < _lengthThreshold ? length : _lengthThreshold]; length -= _lengthThreshold; } } }
/// <summary> /// Recupera o tamanho do item associado com a chave informada. /// </summary> /// <param name="key"></param> /// <returns></returns> public override int GetItemSize(object key) { try { ISizable sizable = _itemDict[key] as ISizable; return((sizable != null) ? sizable.Size : 0); } catch (Exception exception) { Trace.Error("ClrHeapStorageProvider.GetItemSize()".GetFormatter(), exception.GetFormatter()); return(0); } }
/// <summary> /// Get the size of item stored in cache, specified by the passed in key /// </summary> /// <param name="key">key</param> /// <returns>item size</returns> public override int GetItemSize(object key) { try { ISizable item = _itemDict[key] as ISizable; return(item != null ? item.InMemorySize : 0); } catch (Exception e) { Trace.error("ClrHeapStorageProvider.GetItemSize()", e.ToString()); return(0); } }
/// <summary> /// Get the size of item stored in cache, specified by the passed in key /// </summary> /// <param name="key">key</param> /// <returns>item size</returns> public override int GetItemSize(object key) { try { ISizable item = null; lock (_itemDict.SyncRoot) { item = _itemDict[key] as ISizable; } return(item != null ? (item.InMemorySize + Common.MemoryUtil.GetStringSize(key)) : 0); } catch (Exception e) { Trace.error("ClrHeapStorageProvider.GetItemSize()", e.ToString()); return(0); } }
/// <summary> /// Check if store has enough space to add new item /// </summary> /// <param name="oldItem">old item</param> /// <param name="newItem">new item to be inserted</param> /// <returns>true is store has space, else false</returns> protected StoreStatus HasSpace(ISizable oldItem, ISizable newItem, long keySize, Boolean allowExtendedSize) { if (VirtualUnlimitedSpace) { return(StoreStatus.HasSpace); } long maxSize = _maxSize; if (!allowExtendedSize) { maxSize = (long)(_maxSize * .95); } long nextSize = TotalDataSize + newItem.InMemorySize - (oldItem == null ? -keySize : oldItem.InMemorySize); StoreStatus status = StoreStatus.HasSpace; //try //{ // if (SystemMemoryTask.PercentMemoryUsed > 90) // { // if (_extraDataSize > 0) // return StoreStatus.NearEviction; // return StoreStatus.HasNotEnoughSpace; // } //} //catch (Exception) { } if (nextSize > maxSize) { if (nextSize > (maxSize + _extraDataSize)) { return(StoreStatus.HasNotEnoughSpace); } return(StoreStatus.NearEviction); } return(status); }
/// <summary> /// Increments the data size in cache, after item is Added /// </summary> /// <param name="itemSize">item added</param> protected void Added(ISizable item, long keySize) { _dataSize += (item.InMemorySize + keySize); }
public SizeW(int width, int height, ISizable theFather) { mySize = new Size(width, height); father = theFather; ChangeSize(); }
//------------------------------------------------- #region Constructor's Region public SizeW(ISizable theFather) { mySize = new Size(0, 0); father = theFather; ChangeSize(); }
public static void SetSize(this ISizable sizable, Size size) { sizable.Width = size.Width; sizable.Height = size.Height; }
public AspectRatioKeeper(ISizable sizable) { Sizable = sizable; Sizable.PropertyChanged += SizableOnPropertyChanged; Aspect = Sizable.Width / Sizable.Height; }
/// <summary> /// Increments the data size in cache, after item is Added /// </summary> /// <param name="itemSize">item added</param> protected void Added(ISizable item,long keySize) { _dataSize += (item.InMemorySize + keySize); }
/// <summary> /// Check if store has enough space to add new item /// </summary> /// <param name="item">item to be added</param> /// <returns>true is store has space, else false</returns> protected StoreStatus HasSpace(ISizable item, long keySize, Boolean allowExtendedSize) { if (VirtualUnlimitedSpace) return StoreStatus.HasSpace; long maxSize = _maxSize; if (!allowExtendedSize) { maxSize = (long)(_maxSize * .95); } //Keysize will be included in actual cachesize long nextSize = TotalDataSize + item.InMemorySize + keySize; StoreStatus status = StoreStatus.HasSpace; if (SystemMemoryTask.PercentMemoryUsed > 90) { if (_extraDataSize > 0) status = StoreStatus.NearEviction; else status = StoreStatus.HasNotEnoughSpace; } if (nextSize > maxSize) { if (nextSize > (maxSize + _extraDataSize)) status = StoreStatus.HasNotEnoughSpace; else status = StoreStatus.NearEviction; } return status; }
/// <summary> /// Decrement the data size in cache, after item is removed /// </summary> /// <param name="itemSize">item removed</param> public void Removed(ISizable item, long keySize, EntryType type) { _dataSize -= (item.InMemorySize + keySize); }
/// <summary> /// Check if store has enough space to add new item /// </summary> /// <param name="oldItem">old item</param> /// <param name="newItem">new item to be inserted</param> /// <returns>true is store has space, else false</returns> protected StoreStatus HasSpace(ISizable oldItem, ISizable newItem, long keySize, Boolean allowExtendedSize) { if (VirtualUnlimitedSpace) return StoreStatus.HasSpace; long maxSize = _maxSize; if (!allowExtendedSize) { maxSize = (long)(_maxSize * .95); } long nextSize = TotalDataSize + newItem.InMemorySize - (oldItem == null ? -keySize : oldItem.InMemorySize); StoreStatus status = StoreStatus.HasSpace; try { if (SystemMemoryTask.PercentMemoryUsed > 90) { if (_extraDataSize > 0) return StoreStatus.NearEviction; return StoreStatus.HasNotEnoughSpace; } } catch (Exception) { } if (nextSize > maxSize) { if (nextSize > (maxSize + _extraDataSize)) return StoreStatus.HasNotEnoughSpace; return StoreStatus.NearEviction; } return status; }
/// <summary> /// Método acionado quando um item for removido. /// </summary> /// <param name="item"></param> protected void Removed(ISizable item) { _dataSize -= item.Size; }
public static Point GetSize(this ISizable sizable) { return(new Point(sizable.Width, sizable.Height)); }
/// <summary> /// Increments the data size in cache, after item is inserted /// </summary> /// <param name="oldItem">old item</param> /// <param name="newItem">new item to be inserted</param> protected void Inserted(ISizable oldItem, ISizable newItem, long keySize) { _dataSize += newItem.InMemorySize - (oldItem == null ? -keySize : oldItem.InMemorySize); }
/// <summary> /// Decrement the data size in cache, after item is removed /// </summary> /// <param name="itemSize">item removed</param> protected void Removed(ISizable item, long keySize) { _dataSize -= (item.InMemorySize + keySize); }
/// <summary> /// Get the position which would be required to center the specified sizable object to the specified Viewport, assuming is has an origin of (0, 0). /// </summary> /// <param name="obj">The sizable object to center.</param> /// <param name="centerTo">The viewport to center the ISizable to.</param> /// <returns>The position which would be required to center the specified sizable object.</returns> public static Vector2 GetCenterPosition(this ISizable obj, Viewport centerTo) { return(obj.GetCenterPosition(centerTo, (obj is IOriginPositionable ? (obj as IOriginPositionable).Origin : Vector2.Zero))); }
/// <summary> /// Método acionado quando um item for inserido. /// </summary> /// <param name="oldItem">Item anterior.</param> /// <param name="newItem">Novo item.</param> protected void Inserted(ISizable oldItem, ISizable newItem) { _dataSize += newItem.Size - ((oldItem == null) ? 0 : oldItem.Size); }
/// <summary> /// Método acionado quando um novo item for adicionado. /// </summary> /// <param name="item"></param> protected void Added(ISizable item) { _dataSize += item.Size; }
private static Size GetRelativeSize(ISizable child, Size parentSize) { var widthProportion = child.Width / parentSize.Width; var heightProportion = child.Height / parentSize.Height; return new Size(widthProportion, heightProportion); }
public static ISize GetSize(this ISizable sizable) { return(ServiceLocator.CoreTypesFactory.CreateSize(sizable.Width, sizable.Height)); }