CoStream, A Bufferless Pipe Stream
2016-08-23
0 0 0
no vote
Other
Earn points
Translated by maninwest@Codeforge Author:Sergey Nozhenko@CodeProject
CoStream is a bufferless alternative for PipeStream.
Background
In a producer/consumer pattern, if we know that there is a consumer that is guaranteed to read the stream to the end, or dispose it in case it can't, the synchronizing stream doesn't need to maintain its own internal buffer, relying entirely on the buffers provided by the caller(s) of the Read method. In the Read method, CoStream saves the reference to the target buffer and waits until it is filled. The Write method, on the other hand, copies data from the source buffer to the target one, signals to the reader if the buffer is ready and either waits for another Read call if there are some unconsumed data left in the source buffer, or returns to the Write caller.
Using the Code
CoStream cannot be used in a single thread. There should be at least two, reading and writing threads. Both are required to close (or
CoStream is a bufferless alternative for PipeStream.
Background
In a producer/consumer pattern, if we know that there is a consumer that is guaranteed to read the stream to the end, or dispose it in case it can't, the synchronizing stream doesn't need to maintain its own internal buffer, relying entirely on the buffers provided by the caller(s) of the Read method. In the Read method, CoStream saves the reference to the target buffer and waits until it is filled. The Write method, on the other hand, copies data from the source buffer to the target one, signals to the reader if the buffer is ready and either waits for another Read call if there are some unconsumed data left in the source buffer, or returns to the Write caller.
Using the Code
CoStream cannot be used in a single thread. There should be at least two, reading and writing threads. Both are required to close (or
c#
缓存
Related Source Codes
No. 186: DX0110- Source code for community propert
0
0
no vote
No. 219: DX0149- Source code for community propert
0
0
no vote
Verification code identification
0
0
no vote
CSV data analysis tool
0
0
no vote
Source code of hospital medical record information
0
0
no vote
No comment