Following the documentation here: https://docs.microsoft.com/pt-br/dotnet/api/system.io.bufferedstream
Add a buffer storage layer to read and write
transactions in another flow
....
A buffer is a block of bytes in memory used to cache data, thus reducing > the number of calls to the operating system. Buffers Improve Performance > Read & Write
In short, a class to buffer a stream and improve read and write operations.
About your doubts:
"I tested the case where I put the buffer with capacity of 128 bytes and loaded in it 192 bytes, it did nothing" and "What’s the point of him asking for a bufferSize when he doesn’t use it for anything?"
In this case you did not understand well the function of the class size parameter BufferedStream
. See the documentation, first about the parameter in the constructor: https://docs.microsoft.com/en-us/dotnet/api/system.io.bufferedstream.-ctor
A Shared read/write buffer is allocated the first time a
Bufferedstream Object is initialized with this constructor. The Shared
buffer is not used if all reads and Writes are Greater than or Equal
to bufferSize.
Or, in free translation
A shared read/write buffer is allocated at first
since a Bufferedstream object is initialized with this constructor. The
shared buffer is not used if all readings and recordings
are greater than or equal to bufferSize
That is, this parameter serves to define the size of the internal buffer, called here "shared", used by the class BufferedStream
.
Still on the documentation link, after an example code has:
If you always read and write to sizes larger than the size of
internal buffer, Bufferedstream may not even allot the buffer
intern.
That is, you initialized the class with a 128 buffer size, but used 192, so the internal buffer was not even used, and the parameter made no sense.
Even in the documentation link, you have an example of code and a suggestion to test this parameter to determine the best combination with respect to parformance:
Vary the constants dataArraySize
and streamBufferSize
to display
its effect on performance.
In summary, the parameter of bufferSize
serves to define the size of the internal buffer and further optimize operations.