The requirements for input and output buffers are sufficiently different that it would be good to support alternate strategies for each of the two directions.
For input buffers:
- the total required size is known in advance
- for very small buffers it would be better to just allocate one from the heap
- for larger buffers, we can optimize the sizes of the segments given that we know the total size required in advance
For output buffers:
- the total size is NOT known in advance
- most messages will end up being small, but we can't tell in advance
- so we should start with a single relatively small segment (1K?) allocated from the heap
- if that turns out to be enough, great, otherwise start grabbing increasingly larger segments from an underlying source (presumably pooled)
Note: this would not require any new interfaces, just alternate implementations of the IBsonChunkSource interface proposed in CSHARP-1115.