gpt4 book ai didi

c - 浮点缓冲区转换为 unsigned char* 在套接字发送时丢失数据

转载 作者:行者123 更新时间:2023-11-30 18:07:05 25 4
gpt4 key购买 nike

是否有更好的方法通过套接字发送 float 据?下面是发送数据的实现。

static float theOUTPUT[THE_FLOAT_DATA_BUFFER_SIZE];
int size = 2048;
int tb = 0;
int numbytes = 0;
int cs = 256;
unsigned char* buf = (unsigned char*)theOUTPUT;
while(tb < size) {
numbytes = send(sock, buf, cs, 0);
printf("bytes sent: %i\n", numbytes);
tb+=numbytes;
buf+=numbytes;
if(tb >= size) {
break;
}
}

最佳答案

在此代码中,不能保证 sizesizeof(theOUTPUT) 匹配。如果较少,那么您将丢失数据。

关于c - 浮点缓冲区转换为 unsigned char* 在套接字发送时丢失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4999178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com