-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
Description
I didn't see any issues/discussion related to this...
It seems like a significant amount of effort has already gone into maximizing performance of ArrayPool<T>
. How much additional effort would it be to allow 'free' array type conversions? Instead of ArrayPool<byte>, ArrayPool<char>, ArrayPool<float>, ArrayPool<int>, ArrayPool<object>
, etc. all with their own buffer pools, just back everything from ArrayPool<byte>
.
I think the main missing link is a method to change an array's type, or allocate a new array by stealing the buffer from another one. In terms of complexity, would it be similar to the new GC.AllocateUninitializedArray<T>
api?
Random implementation questions:
- Is it impossible to guarantee the old array is unreachable? (Unfortunately, I think yes)
- Is it possible to avoid catastrophic failures if code continued to use the old array? (maybe for unmanaged struct types, maybe not if a int[] field is now actually a byte[])
- Could an Array's data buffer be stored separate from the object header (e.g. allow creating array from Span or pointer/length)