io - Use of Buffer in C++ -


i new c++, learning through accelerated c++ andrew koenig , barbara e. moo.

i unable grasp concept of buffer in c++ book says "most systems take significant amount of time write characters output device, regardless of how many characters there write. avoid overhead of writing in response each output request, library uses buffer accumulate characters written, , flushes buffer, writing contents output device, when necessary. doing so, can combine several output operations single write."

why systems take significant amount of time write characters output device? buffer , why require it?why require flushing buffers?

there multiple reasons leads systems taking significant amount of time i/o operations : device may slow (hard disk drives), may require perform various operations before and/or after writing it, etc.

then, buffer reduces number of interaction device making bigger less frequent read/write. then, reduces overhead necessary perform operation (in case of hard drive, you'll want write big chunk of data infrequently, rather small chunks frequently, costs find write, etc.).

moreover, buffer, can control when want i/o operation done can interesting in particular cases (for example, in real time application, you'll want avoid i/o operation while running time-constrained part of code, storing data in buffer, , doing i/o operations once you've exited time-constrained part of code).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -