[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pnet-developers] MemoryStream oribs
From: |
Chris Smith |
Subject: |
[Pnet-developers] MemoryStream oribs |
Date: |
Sun, 16 Mar 2003 12:25:43 +0000 |
User-agent: |
KMail/1.4.3 |
I've been messing about with memorystream this weekend, and ran into a problem
that took me an hour or so to track down. I can see this happening to other
people, and wonered if it was a bug:
String text = ".... big text > 20 characters ....";
Stream ms = new MemoryStream( 20 );
StreamWriter sw = new StreamWriter( ms, Encoding.ASCII );
sw.Write( text );
sw.Flush();
ms.Seek( 0, SeekOrigin.Begin );
This hangs quite nicely at the flush if 'text' is larger than the memory
stream size (20). In fact it's not just the Flush that hangs. Anything
reading from ms after the sw.Write will hang.
I didn't spot the problem at first because I failed to declare a size for the
MemoryStream at construction, as I had expected the MemoryStream to grow in
size the same way a file stream would.
Doing an ltrace on this running test sees it repeating a bunch of short
memcpy's over and over.
Surely MemoryStream shouldn't just hang! It should perhaps raise an exception
at the least I suppose.
Oh, and a general query to those educated in this area: One other thing that
came up whilst tracking down the hang was that doing a ws.Close after the
sw.Flush and before the ms.Seek - The Seek raises the exception that ms has
already been closed. Is that the expected behaviour? I was trying to close
sw to make sure all had been written to ms, not close ms! Just wondered.....
Chris
--
Chris Smith
Technical Architect - netFluid Technology Ltd.
"Internet Technologies, Distributed Systems and Tuxedo Consultancy"
E: address@hidden W: http://www.nfluid.co.uk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pnet-developers] MemoryStream oribs,
Chris Smith <=