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。
本文分享完毕,希望对大家有所帮助。
下一篇:最后一页
X 关闭
- 1、环球微头条丨bufferedreader_buffer
- 2、现实版福贵大爷已结婚生女 环球热资讯
- 3、百亿私募积极加仓 机构热议底部信号|每日报道
- 4、最资讯丨GOAT德约斩获生涯第23座大满贯&3圈大满贯第一人
- 5、2.0T动力,7座MPV布局,这些SUV仅16万起!燃油/混动任你选!
- 6、zippo打火机油多少钱一瓶_zippo打火机油 环球要闻
- 7、今日热门!烤箱烤面包要多长时间(烤箱烤面包)
- 8、今日淘宝退货退款流程填物流单号_淘宝退货退款流程|全球热点评
- 9、PTT热议BLG击败AL:就逮着上路抓 阿彬化身小惹晒|每日视讯
- 10、速递!今年来最强!京津冀等11省份将开启连续高温模式 局地挑战40℃
-
观热点:通业科技(300960.SZ):2022年度权益分派10派4元 股权登记日6月19日
2023-06-12
-
魔王贝恩霍勒是大马任务吗 魔王贝恩霍勒|每日信息
2023-06-12
-
博汇科技(688004.SH)拟推86.25万股限制性股票激励计划|今日要闻
2023-06-12
-
oppor11s参数上市时间_oppo r11s参数
2023-06-12
-
象山限定!“亚运倒计时100天”纪念封纪念戳即将发售_资讯
2023-06-12