I'm tired of writing:
uses
Dos;
...
begin
TextRec(Output).FlushFunc:=nil;
...all the time in every programming contest I follow. Wouldn't it be better to provide an option or a define or whatever to enable output buffering?

Mailing lists / fpc-pascal / 2008-12
5 messages · 3 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
I'm tired of writing:
uses
Dos;
...
begin
TextRec(Output).FlushFunc:=nil;
...all the time in every programming contest I follow. Wouldn't it be better to provide an option or a define or whatever to enable output buffering?
Flushfunc has nothing to do with output buffering ? SetTextBuf controls the buffering.
Michael.
If the output goes to console (no redirection to file) _and_ FlushFunc doesn't point to nil, it gets called after every Write(Ln) - see fpc_Write_End in /rtl/inc/text.inc.
However, I'm not sure whether it would be appropriate to create a special option just for the use case "participation in contest"... Remember that for the real life situations where the speed of console output may be a limiting factor, one can always decide to redirect the output to a file or e.g. minimize the window (which would speed up the output as well, at least with some target platforms). Moreover, the typing saved by replacing the fragment above with a call to something like
"ForceTextOutputBuffering" (even if that's implemented in unit System and thus no uses clause is necessary) is probably negligible... Moreover, users interested in saving few keypresses can create a unit doing this in its initialization part, so that the fragment could be replaced with something like "uses Buffering" only.
Tomas
@Michael:
Just as Tomas say, FlushFunc gets called when the output goes to console (AFAIK) regardless the SetTextBuf settings.
@Tomas:
OK, for a real world apps that's true. I guess I still have to write those things myself. Btw, is there any difference between code in an initialization section of a unit with the one at the beginning of a program?
On 12 Dec 08, at 22:12, leledumbo wrote:
.
.
OK, for a real world apps that's true. I guess I still have to write those things myself. Btw, is there any difference between code in an initialization section of a unit with the one at the beginning of a program?
The only difference is that beginning of a program is guaranteed to be run after initialization sections of all units, whereas with initialization section of one of used units you need to control the order by the order of units in your uses clause (if the order makes any difference, i.e. if one of the other units may make any changes to the Output variable - however, that isn't that common).
Tomas