-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document existence of buffer for in_channels, and related scenarios #10817
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this - it's definitely good to correct, especially given that the Unix
module already has a warning about in_channel
being buffered. A few things (bizarrely, for one paragraph!):
- The information needs to go in the new
In_channel
module as well. I don't think it should be specifically onopen_in_gen
- it could be an isolated paragraph immediately below the heading inStdlib
and as part of the opening text inIn_channel
(you'll have to check what the HTML output looks like - I can't remember whatocamldoc
does with paragraphs in the middle of modules) - It's nice to mention the alternative for the user who needs unbuffered input:
- Would having an
In_channel
version of AddOut_channel.{is,set}_buffered
to control buffering of output channels #10538 have been useful in your case? (future work, if it all, obviously) - In the meantime, the documentation could mention
Unix.openfile
+Unix.read
as the "unbuffered" way of reading from a file.
- Would having an
stdlib/stdlib.mli
Outdated
@@ -1080,7 +1080,11 @@ val open_in_gen : open_flag list -> int -> string -> in_channel | |||
as described above. The extra arguments | |||
[mode] and [perm] specify the opening mode and file permissions. | |||
{!Stdlib.open_in} and {!Stdlib.open_in_bin} are special | |||
cases of this function. *) | |||
cases of this function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cases of this function. | |
cases of this function. |
For there to be a newline, ocamldoc needs a blank line following (assuming that was what you intended)?
Detailed information should go in In_channel with at most a brief mention in Stdlib. Let's not duplicate things. |
This said, buffered I/O behaves pretty much the same in any language (e.g. stdio.h streams in C, BufferedInputStream in Java, and in_channel in OCaml), so I'm not quite sure what needs to be documented specifically in OCaml. |
I removed my comment from stdlib and added another to in_channel.mli. I also noticed that the Unix module has a lot of these "Beware that input channels are buffered" warnings, but they don't do any harm I suppose. I can rebase/squash the changes against current trunk to tidy things if that would help. Regarding having an unbuffered input channel #10538, I think my use case is probably better handled by normal Unix.openfile etc. |
Not worth keeping open, so closing. I think I was pondering whether buffered I/O could be more "intelligent" i.e. noticing concurrent updates to a file by another process and then refreshing the buffer (or something along those lines). But this isn't the standard behaviour as Xavier says. Sorry for the noise. And thanks to David for the feedback. |
In particular, that the buffer isn't updated automatically when the
underlying file data changes.