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

  • SEARCH
  • Home
  • 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 8646105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:43:03+00:00 2026-06-12T12:43:03+00:00

The title doesn’t make it that obvious what I’m asking, but I have created

  • 0

The title doesn’t make it that obvious what I’m asking, but I have created an algorithm that compresses a bunch of files into a single file, and then decompresses them again. To avoid OutOfMemory Exceptions, I use two fileStreams to, first read segments of data from the original files, and then the other fileStream to write these segments into the final file.

I have included my code excerpt below. In this case, rStream and wStream are already declared accordingly, and the bufferSize is currently at 16 mB. fInfo is the file info for the file we are reading from.

Obviously the higher the bufferSize, the faster the operation is completed. I want to know what the maximum possible bufferSize I should use to maximize the efficiency of the operation?

                int bytesRead = 0;
                long toRead = fInfo.Length - curFileSize;
                if (toRead > bufferSize) { toRead = bufferSize; }
                byte[] fileSegment = new byte[toRead];

                while (bytesRead < toRead)
                {
                    bytesRead += rStream.Read(fileSegment, bytesRead, (int)toRead - bytesRead);
                }

                wStream.Seek(finalFileSize, SeekOrigin.Begin);
                wStream.Write(fileSegment, 0, (int)toRead);
  • 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-12T12:43:06+00:00Added an answer on June 12, 2026 at 12:43 pm

    A buffer of 16 MB definitely sounds like overkill. Usually a few kilobytes is used for a buffer like that. At 16 MB you would have very little gain in making the buffer larger, or none at all.

    Consider that if you are using a large buffer, it won’t fit in the processor cache and would be slower to access. If you make it really large some part of it may even be swapped out to disk, so at that point making the buffer larger would only make it slower.

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

Sidebar

Related Questions

Sorry, that title probably doesn't make much sense, but what I want to know
Yes, the title doesn't make much sense, but here's my situation. I have two
Sorry if the title doesn't make sense. Basically I have a series of strings
I wanna check sharepoint title first and see if the lib doesn't have that
I am sure the title of my question doesn't make much sense. But here
Sorry if that title doesn't make sense, I'm new to Rails and I'm building
The title doesn't actually fully describes the problem, that is: I have a table
That title probably doesn't sound right, but forgive me, I'm learning Rails for the
Sorry if the title doesn't make much sense, if you have a suggestion on
The title doesn't really explain what i want but basically. I have my application

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.