Wednesday, 12 September 2007

lesson 2: Using Common Ref Types II

Understanding Readers & Writers

  • TextReader/TextWriter - abstract classes fro mwhich StreamReader/Writer are derived.
  • StringReader/Writer - to read/write to/fro in-memory strings.
  • StringWriter uses a 'StringBuilder', so it is very efficient at creating ever larger strings.
  • BinaryReader/BinaryWriter - for handling binary data to/from streams (i.e. binary files).
  • long number = reader.ReadInt64(); byre[] bytes = reader.ReadBytes(4);...
  • MemoryStream class - func. to create in-memory streams.
  • When use MemoryStream? Do time-intensive work inthe MemoryStream and then open the dest. file, flush the data to it, and close the file quickly.
  • BufferedStream - to wrap streams to improve performance by buffering reads & writes thro the stream. Writing out data to a stream directly does not perform very well. BufferStream wraps another stream object, to allow for writes to happen to a buffer. Only when the buffer is flushed does the data get pushed into the underlying stream.

No comments: