Skip to content
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

Add suppport for custom ArrayPools #13

Closed
jtmueller opened this issue Jan 27, 2019 · 3 comments
Closed

Add suppport for custom ArrayPools #13

jtmueller opened this issue Jan 27, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@jtmueller
Copy link
Owner

Is your feature request related to a problem? Please describe.
Currently the pooled collections are all hard-coded to use ArrayPool<T>.Shared, but ArrayPool<T> is an abstract class intended to allow for custom implementations. For example, on a resource-constrained device someone might need an ArrayPool of a fixed size, or that pre-allocates arrays or something. At the moment there is no way to get PooledCollections to make use of such a custom ArrayPool.

Describe the solution you'd like
We need a way to optionally specify a custom ArrayPool, and default to ArrayPool<T>.Shared if none is provided. However, passing in an instance of a custom ArrayPool wouldn't work for PooledDictionary or PooledSet, because those types rely on arrays of a private type inaccessible from outside.

Perhaps there's a way to use a generic type parameter to specify the type of a custom ArrayPool, and then create an instance of this type inside the collection code?

@jtmueller jtmueller self-assigned this Jan 27, 2019
@jtmueller jtmueller added the enhancement New feature or request label Jan 27, 2019
@dzmitry-lahoda
Copy link
Contributor

new pooledlist(arraypool x)
{
 pool = arraypool ?? arraypool.shared;
}

I was trying to check how Unity works with fully their own spans-pools for their ECS. But have not found that. I hope arraypool is good abstraction may be implemented on top of Unity primitives.

@jtmueller
Copy link
Owner Author

Yes, exactly, to implement this I'll need to add a new ArrayPool<T> optional constructor parameter. But I can only do it for List, Stack, and Queue. Dictionary and HashSet store a private internal type in an array, so it's not possible to pass in an ArrayPool of the correct type for those classes - they will have to keep using the shared pool.

My comment about possibly creating an instance of the custom pool was a bad idea - it's not much of a pool if each instance of PooledDictionary creates its own pool.

@jtmueller
Copy link
Owner Author

This is now in place for the three collection types I mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants