Hi;
I want to read chunks of 40 Mb out of a 1 Gb file with characters. There are lines in it, but they are just 40-1000 characters long. To do this line for line is much too slow, and things like string'output only read up one line. After reading however, I need a string representation to do my checks and substitutions on each line. AFter this I would write the 40 Mb blocks back into a file. I checked in C++ that it is way faster to use "read" on a stream than to "getline" all the time.
I cannot think of anything reasonable with direct_io. I did find this clumsy solution with streams_io, after reading through the attributes appendix in the reference. It works, but that is all I can say. Taking an example of 10-byte blocks:
Code:
with ada.streams.stream_io ;use ada.streams.stream_io;
with ada.streams ;use ada.streams;
with ada.text_io;
procedure Gettext is
file:file_type;
ostream:stream_access;
bsize:constant integer:=10;
type buf is new string (1..bsize);
remd:natural;
div:natural;
str:buf;
begin
open(file,IN_File,"test.out");
ostream:=stream(file);
remd:=natural(size(file)) rem bsize;
div:= natural(size(file)) / bsize;
for ind in 1.. div
loop
buf'read(ostream,str);
ada.text_io.put(string(str));
end loop;
declare
type buf is new string(1..remd);
str:buf;
begin
buf'read(ostream,str);
ada.text_io.put(string(str));
end;
end;
how do real programmers do this ?