`read`和`sysread`有什么区别? [英] What is the difference between `read` and `sysread`?
问题描述
阅读
和< a href =http://perldoc.perl.org/functions/sysread.html =noreferrer> sysread
的文档非常相似。这两者有什么区别?
read
and sysread
have very similar documentation. What are the differences between the two?
推荐答案
关于 读取
:
-
read
支持PerlIO图层。 -
读取
适用于任何Perl文件句柄 [1] 。 -
读取
缓冲区。 -
read
从8 KiB [2] 的固定大小的块中获取系统中的数据。 -
read
可能会阻止可用的数据少于请求的数据 [3] 。
read
supports PerlIO layers.read
works with any Perl file handle[1].read
buffers.read
obtains data from the system in fixed sized blocks of 8 KiB[2].read
may block if less data than requested is available[3].
关于 sysread
:
-
sysread
不支持PerlIO图层(意味着它需要原始又名二进制句柄。。 -
sysread
仅适用于映射到系统文件句柄/描述符的Perl文件句柄[4] 苏p>。 -
sysread
不缓冲。 -
sysread
执行单个系统调用。 -
sysread
如果可以返回数据,则立即返回如果数据量小于请求金额。
sysread
doesn't support PerlIO layers (meaning it requires a raw a.k.a. binary handle).sysread
only works with Perl file handles that map to a system file handle/descriptor[4].sysread
doesn't buffer.sysread
performs a single system call.sysread
returns immediately if data is available to be returned, even if the amount of data is less than the amount requested.
摘要和结论:
-
读取
适用于任何Perl文件句柄,而sysread
仅限于映射到系统文件句柄/描述符的Perl文件句柄。 -
读取
与选择
[5] ,同时sysread
与兼容
。 -
read
可以为您执行解码,而sysread
则要求您自行解码。 - <$ c对于非常小的读取,$ c> read 应该更快,而
sysread
应该是紧固的r用于较大的读数。
read
works with any Perl file handle, whilesysread
is limited to Perl file handles mapped to a system file handle/descriptor.read
isn't compatible withselect
[5], whilesysread
is compatible withselect
.read
can perform decoding for you, whilesysread
requires that you do your own decoding.read
should be faster for very small reads, whilesysread
should be faster for larger reads.
注意:
-
这些包括,例如,绑定文件句柄和使用
open创建的句柄(我的$ fh,'<',\ $ var )
。
在5.14之前,Perl读入了4个KiB块。从5.14开始,当您构建 perl
时,块的大小是可配置的,默认值为8 KiB。
Before 5.14, Perl read in 4 KiB blocks. Since 5.14, the size of the blocks is configurable when you build perl
, with a default of 8 KiB.
根据我的经验,从普通文件读取时,读取
将准确返回请求的数量(如果可能),但从管道读取时可能返回更少。这些结果无法保证。
In my experience, read
will return exactly the amount requested (if possible) when reading from a plain file, but may return less when reading from a pipe. These results are by no means guaranteed.
fileno
会返回这些值的非负数。例如,这些包括从普通文件,管道和套接字读取的句柄,但不包括[1]中提到的句柄。
fileno
returns a non-negative number for these. These include, for example, handles that read from plain files, from pipes and from sockets, but not those mentioned in [1].
我指的是由 IO :: Select 调用的4个参数。
I'm referring to the 4-argument one called by IO::Select.
这篇关于`read`和`sysread`有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!