Getting fast output

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting fast output

leledumbo
Administrator
Is there any way so that Write(Ln) doesn't flush the buffer after each call (as if it's called to write to a file, I knew it from rtl's file handling source), but only when Flush is called? I found some maniac's code that does it at assembler level, but of course it's platform dependant (i386-linux only). Currently, I get it through the use of:
TextRec(<TextVar>).FlushFunc:=nil;
but this forces me to use SysUtils which increase the executable size significantly. If this is the only solution, then please move the record to System unit (if possible, with FileRec too).
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

Peter Vreman
>
> Is there any way so that Write(Ln) doesn't flush the buffer after each call
> (as if it's called to write to a file, I knew it from rtl's file handling
> source), but only when Flush is called? I found some maniac's code that does
> it at assembler level, but of course it's platform dependant (i386-linux
> only). Currently, I get it through the use of:
> TextRec(<TextVar>).FlushFunc:=nil;
> but this forces me to use SysUtils which increase the executable size
> significantly. If this is the only solution, then please move the record to
> System unit (if possible, with FileRec too).

http://www.freepascal.org/docs-html/rtl/system/settextbuf.html



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

Tomas Hajny
In reply to this post by leledumbo
On Mon, July 21, 2008 07:17, leledumbo wrote:

>
> Is there any way so that Write(Ln) doesn't flush the buffer after each
> call
> (as if it's called to write to a file, I knew it from rtl's file handling
> source), but only when Flush is called? I found some maniac's code that
> does
> it at assembler level, but of course it's platform dependant (i386-linux
> only). Currently, I get it through the use of:
> TextRec(<TextVar>).FlushFunc:=nil;
> but this forces me to use SysUtils which increase the executable size
> significantly. If this is the only solution, then please move the record
> to
> System unit (if possible, with FileRec too).

The two record types are declared in unit Dos too; with smartlinking, this
unit should cause virtually no overhead.

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

leledumbo
Administrator
In reply to this post by Peter Vreman
Oh, yeah! I forgot to mention this. But declaring the buffer will eat spaces ,for instance:
...
var
  Buf: array [0..65535] of Byte;
...
will add 64k to the executable because it's allocated on the stack.
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

Jonas Maebe-2

On 22 Jul 2008, at 06:29, leledumbo wrote:

> Peter Vreman wrote:
>>
>> http://www.freepascal.org/docs-html/rtl/system/settextbuf.html
>> http://www.freepascal.org/docs-html/rtl/system/settextbuf.html
>>
> Oh, yeah! I forgot to mention this. But declaring the buffer will  
> eat spaces
> ,for instance:
> ...
> var
>  Buf: array [0..65535] of Byte;
> ...
> will add 64k to the executable because it's allocated on the stack.

You can also allocate it on the heap.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

Marco van de Voort
In reply to this post by leledumbo
> Peter Vreman wrote:
> >
> >  http://www.freepascal.org/docs-html/rtl/system/settextbuf.html
> > http://www.freepascal.org/docs-html/rtl/system/settextbuf.html 
> >
> Oh, yeah! I forgot to mention this. But declaring the buffer will eat spaces
> ,for instance:
> ...
> var
>   Buf: array [0..65535] of Byte;
> ...
> will add 64k to the executable because it's allocated on the stack.

Huh?

A filebuffer variable must be available always, so it is a global variable.
Global variables are in the datasegment. The datasegment is traditionally
divided into two parts, an initialized part (which goes into the binary) and
the uninitialized (which doesn't go in the binary).

Since the above variable is not initialized, it will not go into the binary.

Unless your platform is somehow different, but even then you can allocate it
on the heap.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

Vincent Snijders
Marco van de Voort schreef:
>> will add 64k to the executable because it's allocated on the stack.
>
> Huh?
>
> A filebuffer variable must be available always, so it is a global variable.

I thought the file buffer variable must available for the time a file is opened and
can be discarded after the file has been closed.


Vincent
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

Marco van de Voort
> Marco van de Voort schreef:
> >> will add 64k to the executable because it's allocated on the stack.
> >
> > Huh?
> >
> > A filebuffer variable must be available always, so it is a global variable.
>
> I thought the file buffer variable must available for the time a file is opened and
> can be discarded after the file has been closed.

True of course. I tried to paint a general case.

If your filehandling is within one procedure it can be on the stack. If that
filehandling is within a class, the buffer can be a member of a class etc.

But in neither of these cases it is in the binary.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

Jonas Maebe-2
In reply to this post by Jonas Maebe-2

On 22 Jul 2008, at 08:06, Jonas Maebe wrote:

> On 22 Jul 2008, at 06:29, leledumbo wrote:
>
>> Peter Vreman wrote:
>>>
>>> http://www.freepascal.org/docs-html/rtl/system/settextbuf.html
>>> http://www.freepascal.org/docs-html/rtl/system/settextbuf.html
>>>
>> Oh, yeah! I forgot to mention this. But declaring the buffer will  
>> eat spaces
>> ,for instance:
>> ...
>> var
>> Buf: array [0..65535] of Byte;
>> ...
>> will add 64k to the executable because it's allocated on the stack.
>
> You can also allocate it on the heap.

But that won't help you in this case, because settextbuf does not  
change the flushing behaviour when writing to the screen. For that,  
you have to follow Tomas' advice.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting fast output

leledumbo
Administrator
Jonas Maebe-2 wrote
But that won't help you in this case, because settextbuf does not  
change the flushing behaviour when writing to the screen. For that,  
you have to follow Tomas' advice.
Done, but I still demand it to be in System unit. That way, no additional unit is needed. Does Delphi declare TextRec and FileRec anyway?