• Post Reply Bookmark Topic Watch Topic
  • New Topic

Buffer and Map  RSS feed

 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

I have come across these terms quite alot but never really understood what they mean. Whenever I do readup on them the explanations are just to complicated or the person has a like for big words. Can someone explain them to me in simple terms please ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both of these terms can be used in a lot of different situations, but most of the time, a "buffer" is an area of memory where you can store things temporarily, until your program needs them, while a "map" in a Java context almost always means an instance of some class that implements the java.util.Map interface (and you can read the Javadoc for that class to learn about it.)

Does that all make sense?
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, that was perfect can you give me an example of the implementation of a buffer ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, like the java.io.BufferedReader class. The idea behind that class is you might call read() to read one character from a file. BufferedReader assumes if you want one character, you'll probably want more, and it's faster to read a lot of characters from a disk all at once than one at a time. So if you ask BufferedReader for one character from a file, it will read one thousand characters and store them in an array. The next time you ask for another character, it will already be in the buffer -- i.e., already in the array in memory -- so the read will be very fast.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. Are there any more buffer classes which handle different things ? Or is buffer reader the only one ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, just in java.io, there's BufferedReader, BufferedWriter, BufferedInputStream, and BufferedOutputStream. The java.nio package has a bunch of *Buffer classes which let you transfer arrays of verious types efficiently between the JVM and the system memory. There's also java.awt.image.BufferedImage, which lets you build up an image in memory before saving it or displaying it. Then there are plenty of other classes that do buffering-related things without having "buffer" in their names! It's a pretty basic and important concept.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. What about this: java.nio.Buffer - I have seen it used in concurrent applications.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, mentioned that above -- there's actually a whole family of those classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!