×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

What is the max length of a buffer Stream.Read and Stream.Write can handle?

What is the max length of a buffer Stream.Read and Stream.Write can handle?

What is the max length of a buffer Stream.Read and Stream.Write can handle?

(OP)
Colleagues,

Here's the code (not mine, vendor's, FYI):

CODE --> C#

private void toStm(Stream input, Stream output)
{  byte[] buffer = new byte[16 * 1024];
   int read;

   while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
      {  output.Write(buffer, 0, read); }

   output.Seek(0, System.IO.SeekOrigin.Begin);
} 

As you can see, the buffer there is 16 Kb.
I checked the possible max length of that buffer, Stream.Length, and there's no definite number (https://docs.microsoft.com/en-us/dotnet/api/system...).
However, judging by the data type - Int64, and assuming it's 32 bit byte, after obvious calculations (2^64 / 32 - 1) we arrive to the number ~576 PiB ("petabyte" or "pebibyte", https://en.wikipedia.org/wiki/Petabyte)...
... which denies any comprehension, let alone credibility.
Hence the question in subject.

AHWBGA!

Regards,

Ilya

RE: What is the max length of a buffer Stream.Read and Stream.Write can handle?

There is no max as such: it is whatever your system can take. Say you have a 4Gb system. Half of it is used for the OS and services. That leaves you 2Gb. Say all the other code and heap allocation takes up 1.5Gb. Effectively, you have 0.5Gb to play with. If you go over that, it may or may not work. The OS may swap stuff into the swap space and give you more memory to play with. This varies from system to system. If you run as a 32 bit program on a 64-bit system, you can't go over (4Gb - other code - stack).

Basically, it isn't worth worrying about until your program crashes with an out of memory error. Even something as big as Visual Studio doesn't use very much memory.

RE: What is the max length of a buffer Stream.Read and Stream.Write can handle?

(OP)
Got it, thank you!

Any idea what might be the compelling reason for that vendor's programmer to have buffer sized only to 16 KB?

Regards,

Ilya

RE: What is the max length of a buffer Stream.Read and Stream.Write can handle?

No reason whatsoever - 16 is a nice round binary number. Psychologically, any factor of two (eg 8, 16, 128) or factor of two minus one (eg 15, 31, 63) makes the reader think the writer knows what they are doing. They could have chosen 10 or 99: it wouldn't have made any difference.

RE: What is the max length of a buffer Stream.Read and Stream.Write can handle?

(OP)
So I thought.
Some programming systems have/had this 16 KB limit on the length of the String memvar (VFP for sure, probably dBase as well, maybe (but not sure about) VB6...)
Thank you, xwb!
Case closed.

Regards,

Ilya

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close