Click here to Skip to main content
15,887,846 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Assalam-o-Alikum!

this is maybe a stupid question but it pops in my head. 3 weeks ago i was doing file handling in C. While testing my prog i deliberately miss typed something and hit enter. but when i tried to move up arrow key to goto the line above and correct thing i can't. like in some text based editors "nano" ,"vi" etc.

My question is well its on the top :D...

My other questions are..

1) what are streams, what are buffers?

2) what do they means by full buffer, line buffer and unbuffered ?

3) the window which opens when we run nano editor. the area where we type is fully buffered ?

what i mean is when i type something and press enter write something in second line but i can go to first line by pressing up arrow key.

Hope you understand my questions :)
Posted
Comments
Sergey Alexandrovich Kryukov 8-Apr-14 14:57pm    
The questions are not stupid, but you can get better results if you read on the topics.
—SA
pasztorpisti 8-Apr-14 18:01pm    
Actually you are talking about two completely different problems. A stream is an "interface" to separate the user of a "data storage" from the actual implementation of the "data storage" (file, pipe, memory buffer, socket, ...). On the other hand moving around a cursor/caret in an editor is rather a combination of a graphical user interface and an associated data structure that holds today usually the whole data in memory (since we have plenty of ram). Usually an editor uses (file)streams only to load a file into an editor or to save the edited data into a file but many different objects can provide a read and/or write stream interface (even the data structure that is used to hold the edited text for the editor). You may also confuse the "file pointer" of some seekable streams with the cursor/caret of the editor, they are totally unrelated in my opinion but you could create connection for example between a cursor/caret and the "file pointer" of a (memory) stream but a cursor/caret alone is just something that belongs to graphical user interface (GUI) programming of textboxes.

1 solution

Please see my comment to the question. Asking such question is not the most efficient way to learn things.

Let me try:
  1. In a nutshell: stream is the important abstraction in programming, and buffer is the detail of its technical implementation used to improve performance of some streams under certain condition. The idea is: you can have fast operations (working with RAM) and slower operations (for example, addressing hard drive). You can improve average performance by reducing number of the use of slower operations.

    This is one of the questions which you would better address to Google, Wikipedia or other source. They explain this matter better than one could do in one Quick Answer:
    http://en.wikipedia.org/wiki/Stream_%28computing%29[^],
    http://en.wikipedia.org/wiki/Standard_streams[^],
    http://en.wikipedia.org/wiki/Data_buffer[^].
  2. Streams can be buffered or not. You can use a stream without any buffer. As simple as that.

    "Fully-buffered" is explained here: http://www.cplusplus.com/reference/cstdio/setvbuf[^].

    "Line buffering" is the concept related to character I/O, as opposed to block I/O. The difference is somewhat artificial, mostly originated from the time when "characters" were represented as single bytes. The concepts are explained here: http://www.gnu.org/software/libc/manual/html_node/Buffering-Concepts.html[^].
  3. "Area" cannot be buffered or not. This is the presentation concept (UI). Some editors (many, in fact) read the document fully in the memory and close the file. Since then, the document is kept in memory and edited, and the file can be independently edited or removed. In cannot work for really big files, because they may be too big to fit even in the addressable space of the virtual memory. Then the file is kept open and the data on the file storage unit is loaded or modified on request. The algorithms for doing that are relatively complex.


Good luck.
—SA
 
Share this answer
 
Comments
pasztorpisti 8-Apr-14 17:06pm    
A five, although depending on the level of knowledge of OP he may need to read something about what an abstraction/interface means, but I hope not. :-)
Sergey Alexandrovich Kryukov 8-Apr-14 17:16pm    
Chances are, OP will need to read about it and think a lot. Often, I mention notions and concepts just to hook up an inquirer, because it's absolutely impossible to cover such broad matters in a Quick Answer.

By the way, it's a bit late but... have you seen my 1st of April publication?
Power Over IP: Testing of the First Experimental Facility.

Hope it can feel you more energetic :-) and fun; and perhaps you can ask me some difficult questions. ;-)

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900