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

纵然是瞬间 提交于 2021-01-27 18:12:48

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/15487546/why-does-system-buffer-blockcopy-take-int-instead-of-long

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!