RE: networkstream perf using ReadByte
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Fri, 27 Oct 2006 06:33:57 GMT
Hello Pmoore,
I think your analysis on the performance hit is reasonable. Actually, the
NetworkStream class(used by the encapsulated network components in .net
such as TcpClient and TcpListener) is just a wrapper, it forward the data
read/write calls to the underlying socket object directly. Thus, if you
call "ReadByte" multiple times, it will perform raw IO operation on the
underlying socket object multiple times, this is expensive.
While you use the "Read" method, you can specify an expected length and
that function will return the actual received data length, in such case, it
only peform IO operation on the underlying socket object once. This will be
much more efficient.
Also, you're right that the operating system's socket implementation for
TCP socket will maintain a buffer internally, however, this is transparent
to us , especially for the .net encapsulated network classes. Anyway, for
IO operation with the Stream class in .net, you should always perfer the
"Read" method with a byte[] buffer instead of use "ReadByte" one by one,
that's the most efficient way.
Please feel free to post here if there is anything else you wonder.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- RE: networkstream perf using ReadByte
- From: Steven Cheng[MSFT]
- RE: networkstream perf using ReadByte
- Prev by Date: Re: DW.NET is unstable on havy loaded servers :(
- Next by Date: How to call WaitForPendingFinalizers from a host
- Previous by thread: DW.NET is unstable on havy loaded servers :(
- Next by thread: RE: networkstream perf using ReadByte
- Index(es):
Loading