A byte stream should be transferred and there is one producer thread and a consumer one.
Speed of producer is higher than consumer most of the time, and I need enough buffered data for QoS of my application.
I read about my problem and there are solutions like shared buffer, PipeStream .NET class …
This class is going to be instantiated many times on server so I need and optimized solution.
Is it good idea to use a Queue of ByteArray ?
If yes, I’ll use an optimization algorithm to guess the Queue size and each ByteArray capacity and theoretically it fits my case.
If no, I what’s the best approach ?
Please let me know if there’s a good lock free thread safe implementation of ByteArray Queue in C# or VB.
Thanks in advance
Most important part is the design of the shared object. In my scenario reader and writer can use separate buffers (big data chunks) independently and then, only accessing a shared FIFO object like a queue should be synchronized. This way lock time is minimized and threads can complete the job in parallel. And with .NET framewok 4.0 implementation of this concept made easy :
There’s a ConcurrentQueue(Of T) Class in System.Collections.Concurrent namespace and arrayByte is a good type to use as queue type for my scenario. There are other thread-safe collections in the namespace.
http://msdn.microsoft.com/en-us/library/system.collections.concurrent.aspx