Re: Help reading structured binary files



I'd certainly agree with J.French's suggestion to read it from a file
into a memory stream in one chunk. But also I'd read it from there into
another memory stream which would (in the end) be your
concatenated string contents. In copying from the first MS to the total
MS I'd change the string length from a length byte to a '=' value ($3D
== 61d), having previously read the length to know how many bytes to
copy. The second memory stream should be allocated a large Capacity to
start with.

While you're doing the MS to MS copying you keep a note of MS2 position
(== final length at end).

_Then_ allocate a string of that length and copy the MS2 into it once
and for all. Allocating a string and concatenating it for each element
of each file is sssslllloooowwww (two memory allocations per element).
I reckon doing it the above way, while slightly more code, would be
much much quicker.

Always try and reduce the number of string memory allocations in any
algorithm.

Alan Lloyd

.



Relevant Pages

  • Re: UDP Sending an array possible?
    ... string data back and forth between two applications. ... array between two .NET applications, I would serialize the array using a ... binary formatter to a memory stream and then turn the resulting binary ... Dim mem As New MemoryStream ...
    (microsoft.public.dotnet.languages.vb)
  • Re: UDP Sending an array possible?
    ... string data back and forth between two applications. ... So, to send an array ... formatter to a memory stream and then turn the resulting binary data into ... Dim mem As New MemoryStream ...
    (microsoft.public.dotnet.languages.vb)
  • Re: UDP Sending an array possible?
    ... string data back and forth between two applications. ... array between two .NET applications, I would serialize the array using a ... binary formatter to a memory stream and then turn the resulting binary ... Dim mem As New MemoryStream ...
    (microsoft.public.dotnet.languages.vb)
  • Re: XMLTextWriter -> utf8 string?
    ... //I'll be writing to this in memory stream ... //This line gets me a string which is junk character no matter ... //This will be the output XML UTF-8 encoded ... XmlDocument xmlDocOutput = new XmlDocument; ...
    (microsoft.public.dotnet.xml)
  • Re: UDP Sending an array possible?
    ... string data back and forth between two applications. ... So, to send an array ... Dim mem As New MemoryStream ... ' serialize the array to the memory stream ...
    (microsoft.public.dotnet.languages.vb)