i created a custom pool like
ArrayPool<byte> pool = ArrayPool.Create( 1MB , 5 )
This would mean that i am creating a new pool with max array size 1 mb and 5 arrays per bucket.
But if i try to rent array of more than 1 MB , i am able to do so. Also , i can rent more than 5 arrays as it would allocate it from next bucket.
So, how does a custom pool helps specifically?
Tagging subscribers to this area: @tannergooding
Notify danmosemsft if you want to be subscribed.
It helps in the case that you don't exceed either of those limits. What those limits should be would be revealed via profiling/tuning for a specific application/code path.
@Clockwork-Muse Okay thanks ! That means if at runtime my app tries to somehow rent more than the limit set, then the memory profiling will be different from what is expected ,right?
But if i try to rent array of more than 1 MB , i am able to do so
ArrayPool, when asked for an array larger than the maximum array size, will simply allocate a new array.
This is true of the Shared ArrayPool as well. So one instance of where you may want to create your own array pool is where you want to pool array objects larger than the default (which I think is 1024虏). So, you might want to make your own pool if you want to pool very large objects. Or perhaps you only want to pool smaller objects, so you might use a lower size.
@ChahatKumar - Yes, but how much would depend on how often that happens. If you're writing a server where you get millions of messages that are 80-100kb, but every month you get one message that for some reason is > 5Mb, profiling is going to say "look, use 100kb as the limit" (and let that 5Mb array get created/dropped as a one-off). If every 100th message is really large, though, you might want to have two separate pools, one larger pool of smaller objects, and one smaller pool of larger objects.
@vcsjones @Clockwork-Muse Got it ! Thanks :)