'Why aren't arrays rented from a shared memory pool by default?
I've been perusing through the high performance library offered by Microsoft, specifically MemoryOwner<T>.
In the 'When should this be used?' section of the documentation the following is said:
A common use case is to replace new T[] array allocations, especially when doing repeated operations that either require a temporary buffer to work on, or that produce a buffer as a result.
Which implies that use of MemoryOwner<T> isn't exclusive to 'repeated operations', which I interpret to mean the initial overhead of renting an array from a shared memory pool VS allocation isn't a large concern.
A bit further down they offer an example where new byte[] is used in a function to read bytes from a stream, and the following is said
If we read a large number of files, we'll end up allocating a lot of new arrays, which will put a lot of pressure over the garbage collector
The new byte[] is refactored to MemoryOwner<byte>.Allocate() as a solution to this problem.
My question is: If renting an array from a shared memory pool is more performant than allocation, and the initial overhead of renting isn't large, why does new T[] not rent from a shared memory pool by default?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
