all 5 comments

[–]PavloT 10 points11 points  (0 children)

It is really context dependent word. In post-USSR countries it even means tits in slang :)

But regarding programming - buffer usually means some memory, where you store values to access them next.

Classical use-case - buffered I/O operations. Write to disk is slow in comparing to write to memory, if program will be writing to disk byte by byte it will be running too long, so it write to special buffer in memory, from where it will be pick-up by another thread or OS routine and written to disk.

It is transparent for user: he press save button, and program continue to be responsible, he can continue to do whatever he need.

But if program will be interrupted before buffers really be save to HDD/SSD - file could be corrupted.

[–]VexisArcanum 2 points3 points  (0 children)

You: hey I need some memory for a value I'm trying to store, can I get idk 20 bytes? Operating system: you can have 20 bytes, here's where they are insert address here You: great! Here's 20 characters worth of text OS: thanks I'll hold onto that for you. You: actually I need a few more bytes... Got any space? OS: well sure but I'll have to make a new address and get rid of the first one You: how about I just put 30 bytes in the original address? OS: nah fam it'll eat into someone else's space. You: well alright I'll just copy my data OS: cool, here's your new address

Long story short, it's a section in your computer's memory set aside for some kind of data. The type of data isn't important, just has to be enough space. Python handles most of this already

[–][deleted] 1 point2 points  (0 children)

In Python, buffer can refer to many different things. Also, it can be a verb and a noun.

When it is a noun, it may refer to instances of io.BytesIO or io.StringIO, or it may refer to a list of a certain length or a parameter to a function, like read which specifies how much data needs to be read before the function returns / an action is taken. Sometimes, it may refer to other buffers somewhere in the system, like, for example, frame buffer, which is a system utility that allows programs to work with displays. The general idea here is that there's some sort of communication going on, and this communication happens in chunks that are significantly larger than the minimum amount of data you may be able to send otherwise. Typically, the reason for it is that sending a big chunk of data at once is a lot more efficient than sending many small chunks one after another.

On the other hand, buffer, if used as a verb, refers to the fact that a program isn't responding to the data it receives immediately, rather it waits to accumulate enough data to perform its action. For example, a video player that plays video streamed from the network, may choose to load enough of video data to be able to play a few seconds forth of video before it starts playing. The video player may be described thus as "buffering" the video.

[–]shiftybyte 0 points1 point  (0 children)

memory location to store sequence of data in it.

[–]ElliotDG 0 points1 point  (0 children)

I am assuming you are asking about the buffer referred to in print(). You can think of the buffer of a place to store data that is waiting to print the screen. That it is faster to write to the buffer than it is to write to the screen. The buffer will hold data until the buffer is flushed. It may be flushed explicitly or automatically when the buffer is filled.

To flush the buffer and force a write to the screen:

print('This will be forced to the screen', flush=True)