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 3287360
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:29:03+00:00 2026-05-17T20:29:03+00:00

The default implementation on Stream creates a new single-byte array and then calls Read.

  • 0

The default implementation on Stream creates a new single-byte array and then calls Read. While this is formally correct, it is inefficient. Any stream with an internal buffer should override this method and provide a much more efficient version that reads the buffer directly, avoiding the extra array allocation on every call.

Taken from the FileStream.ReadByte documentation:

http://msdn.microsoft.com/en-us/library/system.io.filestream.readbyte.aspx

What is the meaing of this and how do I overcome this inefficiency?

  • 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-05-17T20:29:04+00:00Added an answer on May 17, 2026 at 8:29 pm

    This is only of concern when you inherit from Stream. When doing so, you must provide at least a Read method, ReadByte is implemented on top of it in the base class. This is fine, but inefficient when your stream is capable of getting individual bytes directly – the default implementation would then first create a single-byte buffer internally, pass it to ReadByte to fill it, and then return the single byte. If you can implement your buffer so that the single byte can be returned directly, without allocating a temporary buffer, you should do so.

    For the calling code, the only consideration is that when you need to read bytes just to store them in a buffer, Read is often more efficient than ReadByte, even when you’re only reading a single byte – but if you really only need one byte, and the stream implementation you’re using provides an optimized version, ReadByte may actually be faster. If you read individual bytes for immediate processing, ReadByte shouldn’t be a problem at all – after all, most of the standard stream classes are buffered already and should provide an optimized ReadByte. If in doubt, profile.

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

Sidebar

Related Questions

I'm currently using default implementation of STL for VS2005 and I'm not really satisfied
The .NET Console class and its default TextWriter implementation (available as Console.Out and implicitly
I have an implementation of default handler. When it gets to a   in
The default generated hashCode and equals implementations are ugly at best. Is it possible
default is 49 how to edit to higher?
The default shell in Mac OS X is bash , which I'm generally happy
By default each row of a Gridview maps to each row in a datatable
By default IntelliJ IDEA 7.0.4 seems to use 4 spaces for indentation in XML
The default rails XML builder escapes all HTML, so something like: atom_feed do |feed|
By default the webjump hotlist has the following which I use quite often: M-x

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.