D and i/o

Patrick Schluter Patrick.Schluter at bbox.fr
Mon Nov 11 10:14:51 UTC 2019


On Sunday, 10 November 2019 at 20:33:35 UTC, Jonathan Marler 
wrote:
> On Sunday, 10 November 2019 at 19:41:52 UTC, Jon Degenhardt 
> wrote:
>> [...]
>
> For "cat" I believe there is a system call to tell the kernel 
> to forward data from one file descriptor to the other, meaning 
> you could implement cat without ever mapping the data into 
> user-space at all. I'm sure this would be the fastest mechanism 
> to implement cat, and I've seen this system call used by a 
> version of cat somewhere out there.

Looks like sendfile(), which as said is not portable. It exists 
on different Unixes but with different semantics. Requires also a 
bit of work around because of its limitations. On Linux it can 
only send at most 0x7ffff000 (2,147,479,552) bytes for example. I 
used it to implement a cp and it is indeed quite fast and 
definitely easier to use than mmap, which is often very difficult 
to get right (I'm talking C here).






More information about the Digitalmars-d mailing list