LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2012, 11:46 AM   #1
muggabug
LQ Newbie
 
Registered: Aug 2011
Posts: 18

Rep: Reputation: Disabled
Ada: How do I read large blocks of characters and get strings ?


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 ?

Last edited by muggabug; 02-11-2012 at 11:04 AM. Reason: improved improvised solution
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I buffer textinput from file in Ada (Ada newbie) muggabug Programming 3 11-03-2011 01:28 AM
ADA Development tools in Linux for ADA 83 and ADA95 ehudnatan Linux - Software 2 05-11-2011 09:58 AM
LXer: This week at LWN: Large pages, large blocks, and large problems LXer Syndicated Linux News 0 09-27-2007 11:40 AM
Shell script to compare blocks of strings? bruno buys Programming 10 04-15-2006 02:16 PM
Java printing - problem with large strings Andy@DP Programming 2 08-03-2004 02:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration