Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8169983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:01:25+00:00 2026-06-06T21:01:25+00:00

I have to parse a large file so instead of doing: string unparsedFile =

  • 0

I have to parse a large file so instead of doing:

 string unparsedFile = myStreamReader.ReadToEnd(); // takes 4 seconds
 parse(unparsedFile); // takes another 4 seconds

I want to take advantage of the first 4 seconds and try to do both things at the same time by doing something like:

        while (true)
        {
            char[] buffer = new char[1024];

            var charsRead = sr.Read(buffer, 0, buffer.Length);

            if (charsRead < 1)
                break;

            if (charsRead != 1024)
            {
                Console.Write("Here");  // debuger stops here several times why?
            }

            addChunkToQueue(buffer); 
        }

here is the image of the debuger: (I added int counter to show on what iteration we read less than 1024 bytes)

enter image description here

Note that there where 643 chars read and not 1024. On the next iteration I get:

enter image description here

I think I should read 1024 bytes all the time until I get to the last iteration where the remeining bytes are less than 1024.

So my question is why will I read “random” number of chars as I iterate throw the while loop?


Edit

I don’t know what kind of stream I am dealing with. I Execute a process like:

        ProcessStartInfo psi = new ProcessStartInfo("someExe.exe")
        {
            RedirectStandardError = true,
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = true,
        };

        // execute command and return ouput of command
        using (var proc = new Process())
        {
            proc.StartInfo = psi;
            proc.Start();                               

            var output = proc.StandardOutput;  //  <------------- this is where I get the strem

            //if (string.IsNullOrEmpty(output))
            //output = proc.StandardError.ReadToEnd();

            return output;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:01:28+00:00Added an answer on June 6, 2026 at 9:01 pm

    From the docs: http://msdn.microsoft.com/en-us/library/9kstw824

    When using the Read method, it is more efficient to use a buffer that
    is the same size as the internal buffer of the stream, where the
    internal buffer is set to your desired block size, and to always read
    less than the block size
    . If the size of the internal buffer was
    unspecified when the stream was constructed, its default size is 4
    kilobytes (4096 bytes)
    . If you manipulate the position of the
    underlying stream after reading data into the buffer, the position of
    the underlying stream might not match the position of the internal
    buffer. To reset the internal buffer, call the DiscardBufferedData
    method; however, this method slows performance and should be called
    only when absolutely necessary.

    So for the return value, the docs says:

    The number of characters that have been read, or 0 if at the end of
    > the stream and no data was read. The number will be less than or equal
    to the count parameter, depending on whether the data is available
    within the stream.

    Or, to summarize – your buffer and the underlying buffer are not the same size, thus you get partial fill of your buffer, as the underlying one is not being filled up yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse a large XML file and I have two options: Perl
I have a large txt file thar I want to parse in my web
I have a large string I need to parse, and I need to find
I have a large binary file to parse, and i am not sure about
I have the need to parse through a large pipe-delimited file to count the
I have the following PowerShell script that will parse some very large file for
I want to parse a large text file so that it breaks into a
I have a very large XML file that I need to parse so I
I have a pretty large file that I need to parse in php, so
I have a very large data file (2GB-3GB). I need to parse some data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.