I understand that the ArrayPool
class was implemented to pool arrays only.
Can I use the ArrayPool
implementation to pool objects (not arrays)? I don't see why not, except that it is a bit weird that it might return an array larger than what I requested.
I was thinking about something like this:
public class Worker
{
ArrayPool<Channel> channels;
public Worker()
{
channels = ArrayPool<Channel>.Shared;
}
public async Task ExecuteSomething(string message)
{
// It gets a bit weird here...
var rentedChannels = channels.Rent(1);
await rentedChannels[0].DoWork();
channels.Return(rentedChannels);
}
}
For convenience, here is the link to the implementation of ArrayPool<T>
.