Re: BinaryWriter (or streams) slow performance

Tech-Archive recommends: Fix windows errors by optimizing your registry




"Rock2000" <Rock2000@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7AF22646-A323-42A0-8033-88FEEAC0FB51@xxxxxxxxxxxxxxxx
I'm basically converting some Java code to C#, and for ths particular
module
I'm creating a file with a certain format from multiple input files.
The
format is certainly not pretty, but essentially the code is writing a
start
block, which contains a dummy int value for the block size, then it's
writing
the block data, and then seeking back up to fill in the block size
which it
now knows. Then seeking back to where it was to continue (yeah :(, I
didn't
design it). It does this for a ton of nested blocks. The problem is it
doesn't know the size of the block before writing it, and I don't want
to go
and redesign it.

Are the blocks small enough that you could create the block *and
header* in memory, and then write out the whole block in one go?

It varies because the blocks are nested. So it goes from a huge block that
basically surrounds the entire file, to smaller and smaller blocks that
nest
forever.

ASN.1 encodings?

One possible alternative, is to write out the whole file sequentially with
the placeholders, collecting the fixups in memory, and then make a second
pass doing the fixups. Also, try to do the fixups in sequential order (so
add to your collection when you write a placeholder, not when you calculate
the correct value). A LinkedList<long> ought to serve you well, let each
block have a LinkedListNode<long> which is created when you write the node
header, and filled in when you end the node and the length is known (you
could even store the stream.Location of the beginning of the data in that
node meanwhile, to make calculating the length easier). Then when you reach
the end of all your blocks, iterate over the entire list and write in the
corrected values.


.



Relevant Pages

  • Multi-Threading
    ... I have a log file that and collecting infomation from ... getting the info is a problem or is writing it the database, ... is when writing data to the table. ... Do Until intcount> intcount1 ...
    (microsoft.public.dotnet.languages.vb)
  • AIX customer billing system.
    ... A hosting company needs to invoice its customers as per machine usage ... Has anyone tried writing any codes for collecting such info and ...
    (comp.unix.aix)
  • Re: Compiling dbd-oracle on hpux64
    ... I am collecting and writing a new version of the Makefile.pl for Oracle 10 ... Prev by Date: ...
    (perl.dbi.users)
  • Collect all open Windows.Forms and close them
    ... I'm writing an application which should be able to close all open forms ... Thisfore I'm collecting all forms in an arraylist ...
    (microsoft.public.dotnet.languages.vb)