buffer是什么意思(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。
相关文章
- 建行银行装修贷款利率?
- 申请过的网贷怎么注销?
- 网贷举报投诉平台有哪些?
- 什么贷款最好办?
- 001042基金净值查询今天 ?
- i贷今日额度已被抢光,您出手慢了是什么意思?
- 花呗补充资料提额8000可信吗?花呗立即提额方法有吗?
- picc车险电话号人工服务电话
- 农业银行开户行查询短信查询 ?
- 贷款50000一年利息是多少?计算方式有什么?
- 网上好借钱的平台有哪些可靠?
- 用房子贷款10万一年多少利息呢?
- 2018平安i贷几点开额度?
- 在分期乐上借10000得还多少?
- 津巴布韦最大面值货币
- 360借条开通要查征信吗我的征信会不会有影响
- 华融湘江银行大额存单有风险吗?
- 18岁网贷能过的口子
- 西安征信报告打印地点
- 贷款1万元一年利息大约是多少?