CacheTKey, TValueEnsureCapacity Property
Gets or sets whether adding the first item to the cache or resetting
Capacity on a non-empty cache should
allocate memory for all cache entries.
Default value:
, unless you use the
IDictionaryTKey, TValue initializer
constructor,
which initializes this property to
.
Namespace: KGySoft.CollectionsAssembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
public bool EnsureCapacity { get; set; }
Public Property EnsureCapacity As Boolean
Get
Set
public:
virtual property bool EnsureCapacity {
bool get () sealed;
void set (bool value) sealed;
}
abstract EnsureCapacity : bool with get, set
override EnsureCapacity : bool with get, set
BooleanICacheEnsureCapacity If Capacity is large (10,000 or bigger), and the cache is not likely to be full, the recommended value is .
When EnsureCapacity is , the full capacity of the inner storage is allocated when the first
item is added to the cache. Otherwise, inner storage is allocated dynamically, increasing its size again and again until the preset Capacity is reached.
When increasing occurs the storage size is increased to a prime number close to the double of the previous storage size.
When
EnsureCapacity is
, then after the last storage doubling the internally allocated storage can be much bigger than
Capacity.
But setting
to this property trims the possibly exceeded size to a prime value close to the actual capacity.
When cache is not empty and EnsureCapacity is just turned on, the cost of setting this property is O(n),
where n is Count. In any other cases cost of setting this property is O(1).