Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow ArrayPool<T> to share pooled arrays of different types #13398

@kayle

Description

@kayle

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions