Skip to content

Conversation

@noiverree
Copy link

Rent and Return callback raises InvalidOperationException when a pooled object triggers a new rent or return operation within the callback, causing the componentsBuffer to be altered while it is still being enumerated.

Rent and Return callback raises InvalidOperationException when a pooled object triggers a new rent or return operation within the callback, causing the componentsBuffer to be altered while it is still being enumerated.
Forgot to add a bracket (I was editing on GitHub website)
@nuskey8
Copy link
Member

nuskey8 commented Nov 24, 2024

Allocating a new List for every Invoke will result in poor performance. We can use ArrayPool and Span to avoid this.

@nuskey8
Copy link
Member

nuskey8 commented Nov 24, 2024

You can use CollectionsMarshal to extract the internal array of List as a Span, which eliminates the need to enumerate when copying to the buffer, and further speeds up the process, but this is not available in Unity. You can achieve the same functionality by defining a class with the same memory layout as List, extracting the internal array by performing type conversion with UnsafeUtility.As, and creating a Span. (A similar implementation is available in Cysharp/MemoryPack.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants