buffering(buffer)

关于buffering,buffer不少朋友还不清楚,今天小二来为大家解答以上的问题,现在让我们一起来看看吧!

1、是缓冲。

2、缓冲器。

3、System.Buffer 以字节数组(byte[])方式操作基元类型数组,相当于 C 语言的 (char*)int_pointer 指针操作。

4、1. Buffer.ByteLength该方法范围基元类型数组累计有多少字节组成。

5、var bytes = new byte[] { 1, 2, 3 };var shorts = new short[] { 1, 2, 3 };var ints = new int[] { 1, 2, 3 };Console.WriteLine(Buffer.ByteLength(bytes));  // 1 byte * 3 elements = 3Console.WriteLine(Buffer.ByteLength(shorts)); // 2 byte * 3 elements = 6Console.WriteLine(Buffer.ByteLength(ints)); // 4 byte * 3 elements  = 12也就是说该方法结果等于"基元类型字节长度 * 数组长度" 。

6、2. Buffer.GetBytepublic static byte GetByte(Array array, int index)这个方法原型很容易引起误解。

7、var ints = new int[] { 0x04030201, 0x0d0c0b0a };var b = Buffer.GetByte(ints, 2); // 0x03从左到右顺序存储 int,按照小端模式内存数据就是:01 02 03 04 0a 0b 0c 0dindex 2 的结果自然是 0x03。

8、3. Buffer.SetBytepublic static void SetByte(Array array, int index, byte value)有了上面的解释,这个就比较好理解了。

9、var ints = new int[] { 0x04030201, 0x0d0c0b0a };Buffer.SetByte(ints, 2, 0xff);操作前 : 01 02 03 04 0a 0b 0c 0d操作后 : 01 02 ff 04 0a 0b 0c 0d4. Buffer.BlockCopypublic static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)看个例子就明白了。

10、var bytes = new byte[] { 0x0a, 0x0b, 0x0c, 0x0d};var ints = new int[] { 0x00000001, 0x00000002 };Buffer.BlockCopy(bytes, 1, ints, 2, 2);拷贝前 ints 的内存布局:01 00 00 00 02 00 00 00从 bytes Index 1 拷贝 2 个字节到 ints Index 2 后内存布局:01 00 0b 0c 02 00 00 00。

本文到此分享完毕,希望对你有所帮助。

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。系信息发布平台,仅提供信息存储空间服务。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。

本文来自网络,若有侵权,请联系删除,作者:马楠华,如若转载,请注明出处:

发表回复

登录后才能评论