Python是否支持零拷贝I/O? [英] Does Python support zero-copy I/O?

查看:63
本文介绍了Python是否支持零拷贝I/O?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个打开的文件对象,分别是 dest src .打开文件对象 dest 进行写入,将查找位置放置在文件内的某个偏移处,然后打开文件对象 src 进行读取.我需要做的就是简单地从 src 中的当前位置读取到EOF,然后将内容尽快传输到 dest .

I have two open file objects, dest and src. File object dest is opened for writing, with the seek position placed at some offset within the file, and file object src is opened for reading. What I need to do is simply read from the current position in src to EOF and transfer the contents to dest as quickly as possible.

如果我使用Java编程,则可以利用

If I were programming in Java, I could utilize the FileChannel#transferTo() method to perform zero-copy file I/O.

Python还支持零拷贝吗?

Does Python also support zero-copy?

推荐答案

从3.3版开始,Python就有 os.sendfile ,它与各种Unix变体的 sendfile(2)零拷贝I/O接口连接.它对文件描述符进行操作,而不是对一般的类文件对象进行操作.对于较旧的Python,有 py-sendfile .

Since version 3.3, Python has os.sendfile, which interfaces to various Unix variants' sendfile(2) zero-copy I/O interfaces. It operates on file descriptors, not general file-like objects. For older Pythons, there's py-sendfile.

这篇关于Python是否支持零拷贝I/O?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆