microsoft / referencesource

Source from the Microsoft .NET Reference Source that represent a subset of the .NET Framework
https://referencesource.microsoft.com/
MIT License
3.17k stars 1.27k forks source link

List adds a reset size method to reuse memory #151

Closed sunliusi closed 3 years ago

sunliusi commented 3 years ago

A large list can lead to high memory usage. ObjectPool can solve this problem. Is it possible to allow external resizing to reuse memory.

just like:

public class List : IList, System.Collections.IList, IReadOnlyList { private int _size;

        public void Reset(int size)
        {
            this._size = size;
        }
    }
KalleOlaviNiemitalo commented 3 years ago

@sunliusi, I don't think Microsoft intends to add any new features to .NET Framework. You can post this API proposal at https://github.com/dotnet/runtime/issues/new/choose and they can then consider it for .NET 7.

KalleOlaviNiemitalo commented 3 years ago

Overview of .NET Framework:

.NET Framework 4.8 is the last version of .NET Framework, and no further versions will be released.

So, it's pretty clear that List\<T>.Reset(int size) won't be added there.

sunliusi commented 3 years ago

Thanks for reminding. I'll close it. @KalleOlaviNiemitalo