Josh M.
Josh M.

Reputation: 27801

Why does System.Buffer.BlockCopy take int instead of long?

Is there a reason System.Buffer.BlockCopy takes int parameters instead of long for the offset/length of the copy? Streams generally work with long, why would BlockCopy not have an overload that takes long, too?

Upvotes: 2

Views: 1231

Answers (1)

Jim Mischel
Jim Mischel

Reputation: 134035

Because prior to .NET 4.5, no object could exceed 2 gigabytes. So there was no reason to have more than an int to represent the length.

Even in .NET 4.5, although an array can be more than 2 gigabytes in length, it can't have more than 2^31 items. So the maximum size of a byte[] is still 2 gigabytes (minus a little overhead). The maximum size of an int[] is 2^31 items or about 8 gigabytes, etc. See gcAllowVeryLargObjects.

Upvotes: 4

Related Questions