Re: "endl and "\n"
From: Minti (mintiSPAMBLOCK_at_yahoo.com)
Date: 07/07/04
- Next message: Howard: "Re: circular dependencies and typedefs"
- Previous message: Dylan: "Re: circular dependencies and typedefs"
- In reply to: Karl Heinz Buchegger: "Re: "endl and "\n""
- Next in thread: Howard: "Re: "endl and "\n""
- Reply: Howard: "Re: "endl and "\n""
- Reply: Alf P. Steinbach: "Re: "endl and "\n""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 7 Jul 2004 10:59:13 -0700
Karl Heinz Buchegger <kbuchegg@gascad.at> wrote in message news:<40EBB79C.E7B92E7E@gascad.at>...
> dover wrote:
> >
> > For the code, outputfile << *p << endl;
> >
> > Someone suggests: Don't use endl here; it is flushing output stream every
> > time. Use plain '\n'.
> >
> > What's the difference of using "endl" and "\n" above? What's the meaning of
> > flushing output stream? Isn't that what we want?
>
> The point is:
> Most operating systems or most C++ libraries do a sort of buffering.
> If you do an output, the output is not immediatly sent to the
> output device, but instead is buffered until a specific amount of
> buffered output is collected, which is then sent in one chunk to the
> device. The reason why this is done is simply efficiency. To hand some
> data through to the receiving device, the data has to pass various stages
> in either the C++ library and/or the operating system. All of them take
> time and it would be a waste of time to do that for eg. each single
> character.
>
> But sometimes you want exactly that: no buffering, each character is sent
> immediatly to the device as soon as it is available. This is the situation
> where flushing comes into play. It is the request to empty all those buffers
> and sent the data to the device, regardless of buffering strategy.
> Example: If you do debugging the old way by inserting output statements into
> your source code and watching which one you saw last before the crash. Here
> you don't want some buffering to occour and thus you flush the output stream.
Yes, we all know this but what surprises me is that most of textbook
authors pretty much NEVER use "\n", they just keep on using std::endl,
without highlighting the potential loss in efficiency.
-- Imanpreet Singh Arora "In order to paint 6 things are required: i"kaur" #AT# acm #DOT# org spirit, rhythm, thought, scenery, pen and ink" mv kaur singh
- Next message: Howard: "Re: circular dependencies and typedefs"
- Previous message: Dylan: "Re: circular dependencies and typedefs"
- In reply to: Karl Heinz Buchegger: "Re: "endl and "\n""
- Next in thread: Howard: "Re: "endl and "\n""
- Reply: Howard: "Re: "endl and "\n""
- Reply: Alf P. Steinbach: "Re: "endl and "\n""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|