Helps to develop high-performance applications on .NET Framework
Nuget-package (will be available soon).
Value types (structures) support in .NET Framework is a great and fast thing. But sometimes structures can
cause performance problems when they, for example, are frequently passed to
methods that accepts only Object
or interface parameters.
Frequent boxing is a big problem of high-loaded applications cause it produces a lot of objects in heap that then needs to be collected by GC. Unintended load to GC leaves less CPU resources and memory for payload. Sometimes it's very complicated to avoid unnecessary boxing when using external libraries or heavily modifiable code. For such cases using Box() and BoxGeneric() extension methods is the best solution.
Int32 x = 25;
Object xBoxed1 = x.Box();
Object xBoxed2 = x.Box();
(xBoxed1 == xBoxed2) // is true
Both Box<T>()
and BoxGeneric<T>()
extension methods use a multi-level boxed
value cache implemented in BoxedValuesCache<TKey, TValue>
class and avoid
creating a multiple boxed instances of the same value type instance.
BoxedValuesCache<TKey, TValue> class provides a multi-level cache of
boxed structures (TValue
) identified by any key (TKey
). TKey
can be any
type like String
or be the same as TValue, which means that value type
instance identifies its boxed value by itself. BoxedValuesCache<TKey, TValue>
tries to avoid unintended contentions for frequently requested values using
thread-local storages.
BoxedValuesCache is almost the same as BoxedValuesCache<TKey, TValue>
with type arguments places in methods. Note that Box()
extension method is
available for all structures that implements IEquatable<T>
interface.
With Eco Tools each value type instance that needs to be boxed multiple times can be boxed just once which incredibly decrease GC load and memory consumption in most of cases.
.NET Framework provides Garbage Collector that detects unused objects and collects them. In most cases GC do its work well and doesn't require any attention.
But sometimes when system runs under pressure and allocates to much memory, GC (especially in server mode) have not enaugh time to do its job. This means that even if application looses reference to some object it takes a lot of time for GC to collect it and release memory.
In that case the collection speed of GC is less than allocation speed and memory usage of application increases constantly.
To prevent such situation we needs to reuse some object to decrease allocation speed.
Eco Tools Library provides special RecycleFactory base class and IRecyclable interface to implement a simple object pooling mechanism.
Instead of creating objects with new
operator request it from RecycleFactory<T>
calling the Create()
method.
When object that implements IRecyclable
interface is no longer needed call Free()
extension method
to put it back to source RecycleFactory<T>
.
... not finished yet ...
description will be available soon
description will be available soon
description will be available soon