小编Cla*_*ris的帖子

在 Windows 上写入

Windows 是否在非 Cygwin 环境中提供类似于 writev 的任何内容?

理想情况下,答案应该有一个适用于 Windows 的工作示例,大致如下:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/uio.h>

int main() {
  struct iovec iov[2];
  char blah[][20] = { "mickey", " mouse" };
  int fd = open ("/tmp/mice.txt", O_WRONLY | O_CREAT);
  iov[0].iov_base=blah[0];
  iov[1].iov_base=blah[1];
  iov[0].iov_len=iov[1].iov_len=6;
  writev(fd, iov, 2 );
  close(fd);
}
Run Code Online (Sandbox Code Playgroud)

答案应该是如何使用系统调用来解决问题。具体来说,我希望避免将单个缓冲区复制到一个更大的缓冲区中来执行写入。此外,结果写入应该是单个大型写入请求,而不是执行缓冲 IO 的 fwrite 之类的请求。


编辑:13 八月 12

到 Scatter Gather I/O 的链接似乎主要与 TCP/IP 网络有关(确实是 winsock)。另一个建议是 writefilegather 是一种以非常特定的格式写入文件的解决方案。即 writev 使用 iov 容器(任意内存块)写入,而 writefilegather 使用与页表大小对齐的固定缓冲区。

c unix windows file-io

5
推荐指数
1
解决办法
3390
查看次数

标签 统计

c ×1

file-io ×1

unix ×1

windows ×1