Bra*_*riy 3 string size d zero-copy
我有字节数组,定义为指针+大小:
size_t size; // size in bytes
void *data; // NOT zero-terminated string
Run Code Online (Sandbox Code Playgroud)
如何从中构造,最好是零拷贝,"字符串"?
这假定data指向不可变的内存:
string s = (cast(immutable(char)*)data)[0..size];
Run Code Online (Sandbox Code Playgroud)
如果没有,char[]则更合适而不是字符串,或者您可以创建不可变副本.idup.