Текущий архив: 2008.05.11;
Скачать: CL | DM;
Вниз
Чтение файлов Найти похожие ветки
← →
TUser © (2008-03-31 10:40) [0]или Печатаем собственный листинг :)
Стоит задача - читать и на ходу обрабатывать достаточно большой текстовый файл (неск. гигабайт). Предполагаю, что быстрее будет читать блоками. Однако,{$apptype console}
type
CAr = array [0..255] of char;
var s: CAr;
f: file of CAr;
begin
assignfile (f, "test.dpr");
reset (f);
while not eof (f) do begin
read (f, s);
writeln ("""", s, """");
end;
closefile (f);
end.
конечно, не годится, потому что, если число байт в файле не кратно 256, то остаточек не читается.file of char
читает все полностью, но посимвольно. В связи с этим вопрос, - а не читается ли файл с диска блоками и без моих телодвижений. Ну, типа, прочиталось чуть-чуть, хранится в буфере? Интересуют системы NTFS и ext2/3.
зы. TFileStream использовать религия не позволяет.
← →
Правильный_Вася (2008-03-31 10:44) [1]F: TextFile;
ReadLn()
не волнуйся, при последовательном чтении винда за тебя прокэширует
← →
Правильный_Вася (2008-03-31 10:44) [2]F: TextFile;
ReadLn()
не волнуйся, при последовательном чтении винда за тебя прокэширует
← →
clickmaker © (2008-03-31 10:46) [3]а почему бы не CreateFileMapping?
← →
palva © (2008-03-31 10:52) [4]Месяца два назад уже спорили, что не прокэширует.
Нужно описать как безтиповой файл
f: File;
reset его с указанием двух параметров и читать большими блоками при помощи функции blockread. Эта функция возвратит количество, сколько в реальности прочиталось, если блок оказался неполный.
← →
Alien1769 © (2008-03-31 14:14) [5]Reads one or more records into a variable.
Declaration:
procedure BlockRead(var F: File; var Buf; Count: Word
[; var Result:Word]);
where:
F untyped file variable
Buf any variable
Count an expression of type Word
Result a variable of type Word
Target:
Windows, Real, Protected
Remarks:
F is an untyped file variable, Buf is any variable, Count is an expression
of type Word, and Result is a variable of type Word.
BlockRead reads Count or fewer records from the file F into memory, starting
at the first byte occupied by Buf. The actual number of complete records
read (less than or equal to Count) is returned in the optional parameter
Result. If Result is not specified, an I/O error occurs if the number read
is not equal to Count.
The entire transferred block occupies at most Count symbol * RecSize bytes,
where RecSize is the record size specified when the file was opened (or 128
if the record size was not specified). An error occurs if Count symbol *
RecSize is greater than 65,535 (64K).
Result is an optional parameter. If the entire block was transferred, Result
will be equal to Count on return. Otherwise, if Result is less than Count,
the end of the file was reached before the transfer was completed. In that
case, if the file"s record size is greater than 1, Result returns the number
of complete records read.
The current file position is advanced by Result records as an effect of
BlockRead.
← →
Sapersky (2008-03-31 14:38) [6]F: TextFile;
ReadLn()
не волнуйся, при последовательном чтении винда за тебя прокэширует
Прокэширует в данном случае TextFile, у него есть 128-байтный буфер (можно задать больше, см. SetTextBuf).
Страницы: 1 вся ветка
Текущий архив: 2008.05.11;
Скачать: CL | DM;
Память: 0.48 MB
Время: 0.017 c