buffering

Why does printf() not print anything before sleep()?

荒凉一梦 提交于 2019-11-27 12:58:43
问题 I'm just learning C with Kernighan and Ritchie's book; I'm in the basics of the fourth chapter (functions stuff). The other day I became curious about the sleep() function, so tried to use it like this: #include <stdio.h> #include <unistd.h> int main(void) { printf(" I like cows."); sleep(5); return 0; } The problem is the output of the program, it looks like it does the sleep() first and then the printf() , in other words, it waits five seconds and then prints the string. So I thought, maybe

What does “select((select(s),$|=1)[0])” do in Perl?

本小妞迷上赌 提交于 2019-11-27 12:39:23
I've seen some horrific code written in Perl, but I can't make head nor tail of this one: select((select(s),$|=1)[0]) It's in some networking code that we use to communicate with a server and I assume it's something to do with buffering (since it sets $| ). But I can't figure out why there's multiple select calls or the array reference. Can anyone help me out? It's a nasty little idiom for setting autoflush on a filehandle other than STDOUT. select() takes the supplied filehandle and (basically) replaces STDOUT with it, and it returns the old filehandle when it's done. So (select($s),$|=1)

Understanding Ruby and OS I/O buffering

假如想象 提交于 2019-11-27 11:47:58
How does IO buffering work in Ruby? How often is data flushed to the underlying stream when using the IO and File classes? How does this compare to OS buffering? What needs to be done to guarantee that given data has been written to disk, before confidently reading it back for processing? Casper The Ruby IO documentation is not 100% clear on how this buffering works, but this is what you can extract from the documentation: Ruby IO has its own internal buffer In addition to that the underlying operating system may or may not further buffer data. The relevant methods to look at: IO.flush :

Rx IObservable buffering to smooth out bursts of events

戏子无情 提交于 2019-11-27 11:43:09
I have an Observable sequence that produces events in rapid bursts (ie: five events one right after another, then a long delay, then another quick burst of events, etc.). I want to smooth out these bursts by inserting a short delay between events. Imagine the following diagram as an example: Raw: --oooo--------------ooooo-----oo----------------ooo| Buffered: --o--o--o--o--------o--o--o--o--o--o--o---------o--o--o| My current approach is to generate a metronome-like timer via Observable.Interval() that signals when it's ok to pull another event from the raw stream. The problem is that I can't

How can I check if my AVPlayer is buffering?

最后都变了- 提交于 2019-11-27 07:37:43
I want to detect if my AVPlayer is buffering for the current location, so that I can show a loader or something. But I can't seem to find anything in the documentation for AVPlayer. You can observe the values of your player.currentItem : playerItem.addObserver(self, forKeyPath: "playbackBufferEmpty", options: .New, context: nil) playerItem.addObserver(self, forKeyPath: "playbackLikelyToKeepUp", options: .New, context: nil) playerItem.addObserver(self, forKeyPath: "playbackBufferFull", options: .New, context: nil) then override public func observeValueForKeyPath(keyPath: String?, ofObject

Buffered RandomAccessFile java

这一生的挚爱 提交于 2019-11-27 07:00:33
RandomAccessFile is quite slow for random access to a file. You often read about implementing a buffered layer over it, but code doing this isn't possible to find online. So my question is: would you guys who know any opensource implementation of this class share a pointer or share your own implementation? It would be nice if this question would turn out as a collection of useful links and code about this problem, which I'm sure, is shared by many and never addressed properly by SUN. Please, no reference to MemoryMapping, as files can be way bigger than Integer.MAX_VALUE. Edwin Dalorzo Well, I

HTML5 Video buffered attribute features

旧时模样 提交于 2019-11-27 06:45:50
I am designing a custom HTML5 video player. Thus, it will have its own custom slider to mimic the video progress, so I need to understand the entire buffering shebang of a HTML5 video. I came across this article: Video Buffering . It says that the buffered object consists of several time ranges in linear order of start time. But I couldn't find out the following: Say the video starts. It continues upto 1:45 on its own (occasionally stalling perhaps, waiting for further data), after which I suddenly jump to 32:45. Now after some time, if I jump back to 1:27 (within the time range initially

How to buffer stdout in memory and write it from a dedicated thread

馋奶兔 提交于 2019-11-27 03:46:41
I have a C application with many worker threads. It is essential that these do not block so where the worker threads need to write to a file on disk, I have them write to a circular buffer in memory, and then have a dedicated thread for writing that buffer to disk. The worker threads do not block any more. The dedicated thread can safely block while writing to disk without affecting the worker threads (it does not hold a lock while writing to disk). My memory buffer is tuned to be sufficiently large that the writer thread can keep up. This all works great. My question is, how do I implement

Haskell: read input character from console immediately, not after newline

送分小仙女□ 提交于 2019-11-27 02:31:52
问题 I've tried this: main = do hSetBuffering stdin NoBuffering c <- getChar but it waits until the enter is pressed, which is not what I want. I want to read the character immediately after user presses it. I am using ghc v6.12.1 on Windows 7. EDIT: workaround for me was moving from GHC to WinHugs, which supports this correctly. 回答1: Might be a bug: http://hackage.haskell.org/trac/ghc/ticket/2189 The following program repeats inputted characters until the escape key is pressed. import IO import

Python sockets buffering

时光怂恿深爱的人放手 提交于 2019-11-27 01:49:27
问题 Let's say I want to read a line from a socket, using the standard socket module: def read_line(s): ret = '' while True: c = s.recv(1) if c == '\n' or c == '': break else: ret += c return ret What exactly happens in s.recv(1) ? Will it issue a system call each time? I guess I should add some buffering, anyway: For best match with hardware and network realities, the value of bufsize should be a relatively small power of 2, for example, 4096. http://docs.python.org/library/socket.html#socket