You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BufferManager is not the best option, even it's namespace suggests it is intended for particular purpose.
There is shared memory pool optimized for thread local and detecting memory pressure, but it could return size larger than requested, that breaks RMS in the current design and requires a check for length. If the goal is to reduce overall app memory usage and share pools then using the shared pool with the check should be OK, or RMS should be redesigned to use ArraySegments/Memory etc.
There is also a ConfigurableArrayPool but the relevant variable to get exact size MaxBucketsToTry is not configurable. It should be set to zero and != condition in the while loop replaced with <=.
RMS could just extract bucket implementation from ConfigurableArrayPool, it is c.3X faster than ConcurrentStack that is used now. Replacing SpinLock with hand-crafted lock makes it even faster and is appropriate for this case where the work being done inside the lock is literally a couple of instructions.
Summary: for better memory re-usage I suggest using BufferManager type (which is available from .Net 3.0).
New byte arrays are created here: https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream/blob/master/src/RecyclableMemoryStreamManager.cs#L289
Pros:
Cons:
The text was updated successfully, but these errors were encountered: