如何在dart中分配固定长度字符的缓冲区?
我需要分配固定长度的 ASCII 字符缓冲区,因为我从远程设备以随机顺序接收 (index,7-char chunk) 元组。
在 C/C++ 中我会这样做:
char buffer[3*7+1];
memcpy(&buffer[indexOfTheChunk*7],incomingChunk,7);
我应该如何在 dart 中进行?
I need to allocate a buffer of ASCII characters of fixed length because I receive a (index,7-char chunk) tuples in random order from a distant device.
In C/C++ I would do:
char buffer[3*7+1];
memcpy(&buffer[indexOfTheChunk*7],incomingChunk,7);
How should I proceed in dart?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过制作不可生长的
list
:DART还提供
uint8list
专门用于创建8位字节的固定尺寸缓冲区的类。如果您需要稍后从ASCII字节中提取DART
字符串
,则可以调用ascii.decode
在list< int< int>
/uint8list
上。You can create a fixed-size buffer by making a non-growable
List
:Dart also provides a
Uint8List
class specifically for creating fixed-size buffers of 8-bit bytes.If you need to extract a Dart
String
from the ASCII bytes later, you can callascii.decode
on theList<int>
/Uint8List
.