A high-performance, memory-optimized list to reduce GC pressure. This class is intended for scenarios where performance and memory allocation are critical. It is not thread-safe by default yet.
The differences from the generic List in .NET are as follows:
Key Differences:
-
Optimized Memory Management (Array Pooling): Instead of allocating a new array in memory each time the capacity is increased and leaving the old one for the Garbage Collector (GC), we use ArrayPool. This significantly reduces the pressure on the GC, especially in scenarios where lists are frequently created, destroyed, or resized. This is the biggest difference and the main advantage of this class over the standard List.
-
Use of Span and Memory: For AddRange operations, we use Span. This structure allows us to work directly and very efficiently with a portion of memory, preventing unnecessary data copying.
-
Implementation of IAsyncEnumerable: For asynchronous iteration, we implement this interface, which allows you to easily iterate over the list using await foreach. This capability is not available in the standard List.
-
Support for IEnumerable for foreach: For full compatibility with standard foreach loops, we provide an optimized implementation of the IEnumerable and IEnumerator interfaces.