• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

buffer, buffered, buffering ?

 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
While reading up on I/O for SortNames I've met the class BufferedReader and BufferedWriter. Discussions about earlier assignments mentioned the use of StringBuffers.
I'm wondering if someone could give an explanation of what "buffer", "buffered" or "buffering" means in programming in a real general sense. I have to admit that I haven't looked into it too deeply yet, but I'd like to be able to start with a simplistic understanding of the basic concept.
Up 'til now, the only buffers I've dealt with have had to do with buffer zones and buffered aspirin.
Thanks a buff, unh, a bunch,
Pauline
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Buffering is a term normally associated with I/O. This could be I/O to a screen, file or even to a communications line. Basically anywhere where data read/written to a device.
I think a mouse is an exception but don't quote me on that.
I/O is normally "expensive" in terms of the number of CPU's it uses and the time it takes (its slow !!!).
Buffering is a way of "saving up" bytes that have to be written to the I/O device.
This is done for two reasons.
  • Each device has its own unique characteristics. one of these is, it reads/writes a certain number of bytes at a time. There are physical reasons for that.
  • Because I/O is slow you don't want it to affect the other processes in the CPU too uch.

  • Let me explain using an example.
    Say for instance you want to write a record of 80 characters to a file.
    You have 1000 of these records.
    OK if you don't buffer the records you write 1,000 x.
    Thus potentially interrupting other processes 1,000 X.
    And potentially wasting space. (depending on how the device handles the I/O)
    Lets say you BUFFER the data in a buffer of 800 bytes. So 800 bytes is set aside in memory. If you write your record now its saved into memory untitill the buffer is full or overflows. So you will only have a total 100 physical writes. Thus making more effective use of the computer and device.
    Buffering has one disadvantage. If the program crashes when you write say the 9 record. You will loose all 9 the records that where in the buffer at the time of the crash.
    and that's all I have time for right now
    [This message has been edited by Johannes de Jong (edited October 12, 2001).]
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Building on another benefit of buffering from what JdJ said, it also allows you to manipulate the data in the buffer without having to go through and constantly do I/O stuff. You can read data from somewhere, it goes into the buffer, and now you can make your changes directly to the buffer, and when you are done, it is all flushed back to whatever storage the original data was held on. Much quicker than constantly accessing the file or database. Another reason for doing it this way is if you decide that you don't want the changes made in the buffer to actually be made to the data, you can just clear out the buffer, without having to go back and change the data back to its original state.
Of course, you still have the major drawback that JdJ mentioned. Since the buffer and whatever work your doing resides in memory, unless there is a log that is kept of the changes being made, if the system crashes, you have to start all over again.
Hope that gives a little more insight
Jason
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
buffer

A buffer is a data area shared by hardware devices or program processes that operate at different speeds or with different sets of priorities. The buffer allows each device or process to operate without being held up by the other. In order for a buffer to be effective, the size of the buffer and the algorithms for moving data into and out of the buffer need to be considered by the buffer designer. Like a cache, a buffer is a "midpoint holding place" but exists not so much to accelerate the speed of an activity as to support the coordination of separate activities.

This term is used both in programming and in hardware. In programming, buffering sometimes implies the need to screen data from its final intended place so that it can be edited or otherwise processed before being moved to a regular file or database.

Reference
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well that's the official explanation
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, thanks everyone, that helps a lot. Regular english's "buffer zone" isn't too far off.
The http://whatis.techtarget.com site is a great reference, Marilyn, thanks. It seems to be quite complete as proven by using this test word.


[This message has been edited by Pauline McNamara (edited October 12, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic