Doker wrote:
Doker pisze:
>Jon Skeet [C# MVP] pisze:
>>Doker <do****@wp.plwrote:
The GetBuffer method would appear to be a pretty good indication
that it's just one array:
And what happens when where comes more data? More than the capacity
of the array.
A new buffer is created to hold the previous contents and the new
contents. It's always in a single buffer though.
So what happens when i get the buffer and in the meantime some data
comes? New array is created and the data from the previous one is
copied into the new larger? That would be...
Okey, i've checked it.
It should be allright as long as you lock on the buffer and pin it.
Yes, if you change data that you use in more than one thread, you always
need to synchronise it.
Preferrably you should not lock on the buffer, but a separate private
object that is only used for the locking and nothing else. This prevents
deadlocks, and also the misconception that the lock statement protects
the object that is used for the lock in any way.
Note that when locking, you need to use it on all code that accesses the
stream, both the code that reads it and the code that writes it,
otherwise it's not doing any good at all.
--
Göran Andersson
_____
http://www.guffa.com