Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buffered vs non buffered, which one to use?

I am sorry if this is a duplicate but I was not able to find a definitive answer to what is the best practice for each type.

I would like to know what the appropriate conditions are that define when to use BufferedReader vs FileReader or BufferedInput/OutputStream vs FileInput/OutputStream? Is there a formula of sorts that will always tell you what is appropriate?

Should I just always used buffered?

Thanks

like image 718
stackMe Avatar asked Jul 06 '09 18:07

stackMe


People also ask

Is unbuffered I O more efficient than buffered I O?

Unbuffered output is generally better when you already have large buffers to send -- copying to an intermediate buffer will not reduce the number of OS calls further, and introduces additional work.

What is the difference between a buffered solution and a non-buffered solution?

A buffered solution is a solution in which a buffer is added in a small quantity. During titration, when any solution is added to the buffered solution, the pH of the solution does not change. A non-buffered solution is a solution in which a buffer is not added in the solution.

What's the difference between buffered and unbuffered paper?

For example, if a material is meant to have a slightly acidic composition, it should not be stored with buffered tissue as the neutralization of the material may be detrimental over time. Unbuffered Tissue is pH neutral, and is preferred when storing materials that by nature have a more acidic composition.

What is the main difference between buffered and unbuffered I O?

With buffered I/O, there is a lot of data copying happening: program structures –> FILE buffer –> kernel buffer –> disk. With unbuffered I/O, the copy to the FILE buffer is avoided, and with scatter/gather I/O, the kernel might be able to avoid a copy into its own buffers.


1 Answers

Use a buffer if the stream is going to have lots of small access. Use unbuffered if you are going to have relatively few, relatively large accesses.

like image 70
Tom Hawtin - tackline Avatar answered Sep 25 '22 21:09

Tom Hawtin - tackline