This i found on the oracle docs and i don't understand why using unbuffered I/O is not preffered? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

This i found on the oracle docs and i don't understand why using unbuffered I/O is not preffered?

Most of the examples we've seen so far use unbuffered I/O. This means each read or write request is handled directly by the underlying OS. This can make a program much less efficient, since each such request often triggers disk access, network activity, or some other operation that is relatively expensive. To reduce this kind of overhead, the Java platform implements buffered I/O streams. Buffered input streams read data from a memory area known as a buffer; the native input API is called only when the buffer is empty. Similarly, buffered output streams write data to a buffer, and the native output API is called only when the buffer is full.

18th Mar 2020, 5:08 AM
parag sahu
parag sahu - avatar
1 Answer
+ 1
Buffered I/O is usually much faster. 1. Access to memory is much faster than to a disk. 2. The call of the API functions itself also takes time. This is especially noticeable when writing small amounts of data in a loop. For example, if you write sequentially only 1 byte to a file but 1000 times in a loop, then most of the time will be spent on tasks associated with calling the API functions. When using buffered I/O, calling API functions will be much less likely (data will be written to disk in one large piece when the buffer will be full).
18th Mar 2020, 6:41 AM
andriy kan
andriy kan - avatar