Assign a large buffer
Mikako-ff opened this issue · 3 comments
According to the Readme.md, as follows.
You can also request a stream with an initial capacity;
if that capacity is larger than the small pool block size, a single large buffer will be assigned from the start.
Should the capacity be specified in the "requiredSize" of the GetStream function?
I tried below, but, the large pool sizes remained zero.
namespace ConsoleApp1
{
class Program
{
private static readonly RecyclableMemoryStreamManager manager = new RecyclableMemoryStreamManager(int.MaxValue, int.MaxValue);
static void Main(string[] args)
{
using (var stream = manager.GetStream("256MB", 256 * 1024 * 1024)) { Print(); } // > DefaultBlockSize = 128KB
Print();
using (var stream = manager.GetStream("1GB", 1024 * 1024 * 1024)) { Print(); }
Print();
}
private static void Print()
{
Console.WriteLine($"LargePoolFreeSize={manager.LargePoolFreeSize}, LargePoolInUseSize={manager.LargePoolInUseSize}, ");
}
}
}
Thank for you the report. This looks like some out-of-date documentation. There are overloads of GetStream
that take an asContiguousBuffer
that should be used if you want to force it to come from the large pool. Otherwise, blocks are used.
Thank you for your reply.
I tried it as below.
The LargePoolFreeSize was still zero.
Is it the correct behavior?
private static readonly RecyclableMemoryStreamManager manager = new RecyclableMemoryStreamManager(int.MaxValue, int.MaxValue);
static void Main(string[] args)
{
using (var stream = manager.GetStream("256MB", 256 * 1024 * 1024, true)) { Print(); } // > DefaultBlockSize = 128KB
Print();
using (var stream = manager.GetStream("1GB", 1024 * 1024 * 1024, true)) { Print(); }
Print();
}
/* result *
LargePoolFreeSize=0, LargePoolInUseSize=268435456,
LargePoolFreeSize=0, LargePoolInUseSize=0,
LargePoolFreeSize=0, LargePoolInUseSize=1073741824,
LargePoolFreeSize=0, LargePoolInUseSize=0,
*/
This was due to the DefaultMaximumBufferSize setting (128MB).
It is solved. Thank you.