8000 fix: making a copy list of componentsBuffer by noiverree · Pull Request #3 · annulusgames/uPools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: making a copy list of componentsBuffer #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

noiverree
Copy link
8000

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
0