<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:12pt"><div>I would define only 2 i/o functions:<br><br>size_t read(void[] b);<br>size_t write(const(void)[] b);<br><br>And then the various paraphernalia around it (close, open, etc).<br><br>The reason to use void[] is because any array data type can be passed to it without casting (imagine you wanted to read an array of ints).<br>
<br>
Reading and writing a single byte should be discouraged with unbuffered streams. This is how it is in most I/O libs. You build your unbuffered I/O to abstract the OS functions, then build your buffered I/O and fancy functionality on top of it.<br><br>-Steve<br></div><div style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Lars Tandle Kyllingstad <lars@kyllingen.net><br><b><span style="font-weight: bold;">To:</span></b> Discuss the phobos library for D <phobos@puremagic.com><br><b><span style="font-weight: bold;">Sent:</span></b> Mon, May 10, 2010 8:14:26 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [phobos] UnbufferedFile, or, abstracting the File ranges<br></font><br>
Well, that would at least mean less work for me. :)<br><br>Which I/O methods should it contain, then, in your opinion? Would<br><br> bool read(ref ubyte b);<br> size_t read(ref ubyte[] b);<br> void write(ubyte b);<br> void write(ubyte[] b);<br><br>suffice?<br><br>-Lars<br><br><br><br>On Mon, 2010-05-10 at 05:02 -0700, Steve Schveighoffer wrote:<br>> Re: byLine and byChunk, I don't think these are a good idea on<br>> unbuffered files.<br>> <br>> For example, your current implementation will be extremely slow.<br>> Reading one char at a time is OK on a buffered file, because most<br>> times its just a simple fetch of a char from a buffer. But your<br>> implementation reads a single character at a time from the actual file<br>> on disk, a very slow operation.<br>> <br>> I think unbuffered files are good for
when you want to handle the<br>> buffering yourself, or when you want to pass them to child processes.<br>> <br>> -Steve<br>> <br>> <br>> <br>> <br>> ______________________________________________________________________<br>> From: Lars Tandle Kyllingstad <<a ymailto="mailto:lars@kyllingen.net" href="mailto:lars@kyllingen.net">lars@kyllingen.net</a>><br>> To: Phobos mailing list <<a ymailto="mailto:phobos@puremagic.com" href="mailto:phobos@puremagic.com">phobos@puremagic.com</a>><br>> Sent: Mon, May 10, 2010 7:40:15 AM<br>> Subject: [phobos] UnbufferedFile, or, abstracting the File ranges<br>> <br>> In the process of designing std.process it has become obvious, as<br>> pointed out by Steve, that Phobos needs facilities for unbuffered I/O.<br>> To that end, I've started writing an UnbufferedFile type, the current<br>> status of which can be seen here:<br>> <br>>
Code:<br><span>> <a target="_blank" href="http://github.com/kyllingstad/ltk/blob/master/ltk/stdio.d">http://github.com/kyllingstad/ltk/blob/master/ltk/stdio.d</a></span><br><span>> Docs: <a target="_blank" href="http://kyllingen.net/code/ltk/doc/stdio.html">http://kyllingen.net/code/ltk/doc/stdio.html</a></span><br>> <br>> (Disclaimer: This is very much a work-in-progress, there's lots of<br>> stuff<br>> that needs to be added yet, and I'd be surprised if there wasn't lots<br>> of<br>> room for improvement, performance-wise.)<br>> <br>> <br>> Now, while writing this it has kind of annoyed me that I have to write<br>> new implementations of the byLine and byChunk ranges. I've personally<br>> found them incredibly useful, so I want them in UnbufferedFile, but<br>> the<br>> ones in std.stdio are tailored for File.<br>> <br>> I therefore suggest we try to abstract
these ranges, so they can<br>> operate<br>> on general types that define a set of primitives such as read(),<br>> readc()<br>> and readln().<br>> <br>> Are there problems with this? Any comments?<br>> <br>> -Lars<br>> <br>> _______________________________________________<br>> phobos mailing list<br>> <a ymailto="mailto:phobos@puremagic.com" href="mailto:phobos@puremagic.com">phobos@puremagic.com</a><br><span>> <a target="_blank" href="http://lists.puremagic.com/mailman/listinfo/phobos">http://lists.puremagic.com/mailman/listinfo/phobos</a></span><br>> <br>> <br>> _______________________________________________<br>> phobos mailing list<br>> <a ymailto="mailto:phobos@puremagic.com" href="mailto:phobos@puremagic.com">phobos@puremagic.com</a><br>> <a href="http://lists.puremagic.com/mailman/listinfo/phobos"
target="_blank">http://lists.puremagic.com/mailman/listinfo/phobos</a><br><br><br>_______________________________________________<br>phobos mailing list<br><a ymailto="mailto:phobos@puremagic.com" href="mailto:phobos@puremagic.com">phobos@puremagic.com</a><br><a href="http://lists.puremagic.com/mailman/listinfo/phobos" target="_blank">http://lists.puremagic.com/mailman/listinfo/phobos</a><br></div></div>
</div><br>
</body></html>