[fpc-devel] TBufferedFileStream

José Mejuto joshyfun at gmail.com
Sat Sep 3 22:28:16 CEST 2016


El 03/09/2016 a las 22:15, Michael Van Canneyt escribió:

>> Added to the bugtracker implementation of TBufferedFileStream, there
>> is one compatibility issue note in the bug entry.
>>
>> http://bugs.freepascal.org/view.php?id=30549
>
> Nice. I have assigned this to myself.
>
> Out of curiosity:
> Why do you think this is needed ? Is the caching provided by most of the
> operating systems not enough ?

Hello,

1) Delphi compatibility (It is available in Delphi).

2) TFileStream basically is a frontend for FileRead and FileWrite 
(Talking about Windows) and once you invoke one of those you enter in 
multithread contention, thread swapping, and maybe kernel mode (I'm not 
sure) so if you read or write small pieces of data from files the 
performance is very poor. Typical example is TFileStream.GetByte which 
I'm using in a parser, because the file could be very big, and I don't 
want to read everything in a TMemoryStream, performance of 
cache/buffered and regular is dramatically different:

----------------------------------------------
CACHE 1000000 byte sequential reads in 46 ms.
FILE 1000000 byte sequential reads in 2200 ms.
----------------------------------------------

And this result is with the system cache hot (in fact the full file is 
in system cache).

In the other hand a cache system is powerful than a buffered system if 
you are writing something like a filesystem over a TFileStream where you 
may need to jump here and there to read data, file allocation tables, 
attributes, and so on, in this case a cache with multiple pages instead 
just one improves the result (avoid multiple reads in the same zones).

-- 




More information about the fpc-devel mailing list