Re: Is this not plain wrong, BinaryFormatter

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Alexander Muylaert (Remove_amg_at_pandora.be)
Date: 06/07/04


Date: Mon, 7 Jun 2004 21:28:01 +0200

So...

Two possible fixes for me.

* I write my own BinaryWriter. (with normal behaviour)
* I pass the writer as a Parameter

Both sollutions suck. The first gives me a ton of extra work. The second
is even worse, by passing the writer as a parameter, I need to use the
writer to stream something. Wich perhaps I don't want, or I should access
the BaseStream property. But ...

Hmmm

Who's idea was this and what was (s)he thinking...

Rule n°1: Free whatever you create (even with GC this one applies, I adore
the "using" statement)
Rule n°2: Don't free something that you didn't create.
Rule n°3: First create the object, next Implement the dispose, third
implement the thing inbetween.

Even when you have no GC the above to rules will prevent all leaks and null
pointer exceptions. One should only apply these three very simple rules,
extremely strictly. No buts... :-)

Imho this has nothing to do with GC, closing the stream is just a bad idea
and makes the binarywriter less interesting for me. Especially in the
situation I mentioned. And trust me, this happens a lot.

Kind regards

Alexander



Relevant Pages

  • Re: ensure buffer flushed to file
    ... Does anyone know why BinaryWriter does not offer an AutoFlush option, ... instance of my file-writer class to initiate the stream and the writer, ... flushing, closing, disposing portion of my code). ... BinaryWriter writer = new BinaryWriter; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ensure buffer flushed to file
    ... my file-writer class to initiate the stream and the writer, ... written to file when the associated BinaryWriter is closed? ... BinaryWriter writer = new BinaryWriter; ... stream also flushes it, so you don't need Flush before Close. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Inheritance problem with BinaryWriter
    ... requests for you, why are you putting the values in a Queue? ... You do realize That calling MyBase.BaseStream forces the writer to be ... Does your QueuedBinaryWriter have to inherit from BinaryWriter? ... > Public Overloads Overrides Sub Write ...
    (microsoft.public.dotnet.languages.vb)
  • Socket mit Network-Byte-Order (Motorola-Format)- Client und Server
    ... BinaryWriter.Write// string ... Martin muss Network-Byte-Order verwenden. ... Die String-Methoden von BinaryReader / BinaryWriter verwenden eine andere ... // Create a binary writer to be used for writing ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: BinaryWriter (or streams) slow performance
    ... a BinaryWriter, and found some seemingly poor performance. ... Getting the Position of the baseStream of the writer takes more then ... Granted I should try to avoid that, but shouldn't this be a no-op ... Shouldn't it try to update the buffer if it hasn't been written out yet and ...
    (microsoft.public.dotnet.framework.performance)