Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why we need Buffer ?  RSS feed

 
Harish Tiruvile
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody tell me what is the need of Buffer in java
 
kotha vijaybabu
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a Buffer can improve performance by buffering data.

it wd b useful while playing with large amount of data



-------------------------------------

vijay
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say you ask to read one byte at a time. If that translates literally to moving the read head on a disk and reading one byte it takes a while. When you ask for the next byte it has to do all that work again. Buffering looks ahead some amount. When you ask for one byte it reads 512 or 1024 or whatever it thinks will be a good balance between reducing reads and chewing up some memory. It only moves the read head once and the OS and hardware are probably both optimized to read blocks very quickly. Your next few reads only fetch from the buffer instead of doing all the disk work. Eventually you read all of one buffer and it has to get another.

Good clean fun?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!