LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 11-01-2011, 03:53 PM   #1
muggabug
LQ Newbie
 
Registered: Aug 2011
Posts: 18

Rep: Reputation: Disabled
How do I buffer textinput from file in Ada (Ada newbie)


Hi,

I am trying to learn Ada/Gnat,and am a bit stuck on the I/O. Maybe someone has a quick tip for me.
I am reprogramming something I had done in C++. Most of it is straightforward, except the input side. Get_Line is much to slow, so I am trying to loop reading into a stringbuffer of, say 50 Mb, , to extract and handle the separate lines later on.

I have tried to use 'read on an unbounded string, but this loads strings with 80 chars at a time and crashes at the end. What is the right way to do this ?
Code:
with Ada.Text_IO,Ada.Integer_Text_IO, ada.streams.stream_io,Ada.Strings.Unbounded ;
use Ada.Text_IO,Ada.Integer_Text_IO, ada.streams.stream_io,Ada.Strings.Unbounded  ;
with Ada.Direct_IO;

procedure CompareC is

  subtype unstring is Unbounded_string;
  package unString_IO is new Ada.Direct_IO (unstring);
  chunk: unstring;
  unb_File :  unString_IO.File_type;
  count : integer :=1;
  begin
     unString_IO.open( unb_file,unstring_IO.in_file, "testfile" );
     while not unstring_IO.End_of_File( unb_file ) loop   
       unString_IO.Read  (unb_File, Item => chunk); 
-- write etc...
      end  loop;
  unString_IO.Close( unb_file );
  Put("Done");

end CompareC;
I know, I should really buy the book, but I am just trying if Ada is worth it .Sites like http://www.infres.enst.fr/~pautet/Ada95/a95list.htm and Big Book of Ada Linux are not very helpful inthis particular thing
 
Old 11-02-2011, 11:38 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Ada "Get_Line" *should* be the best way to go.

If it's "too slow", then I'm guessing the problem might be in the Ada I/O itself. In which case the solution might be to write it something *besides* Ada ("pragma interface" to a C/C++ I/O routine, for example).

IMHO .. PSM
 
Old 11-02-2011, 05:15 PM   #3
muggabug
LQ Newbie
 
Registered: Aug 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
To be more precise, the get_line may not be slow, but on a 1 gig file with lines of less than 300 chars it takes too much time to read the whole file.
In c++ this takes a lot of time as well. That is why, in c++, I replace the getline routine by a read on an ifstream, which puts 50 Mb at a time into memory. I am trying to get that done in Ada.

Last edited by muggabug; 11-02-2011 at 05:18 PM.
 
Old 11-03-2011, 01:28 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Off: Sadly, on a UNIX platform, if you want performance, you have to do it in C, using read(2) and write(2) system-calls.
 
  


Reply



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
ADA Development tools in Linux for ADA 83 and ADA95 ehudnatan Linux - Software 2 05-11-2011 09:58 AM
Who is still using Ada programming language? nadavvin Programming 8 01-26-2007 12:49 PM
Missing ADA corbis_demon Linux - Newbie 1 07-05-2004 10:18 AM
no support for ADA corbis_demon Linux - Newbie 0 07-03-2004 09:17 AM
Debugging Ada programms gluon Programming 0 11-07-2001 03:19 AM

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

All times are GMT -5. The time now is 05:57 PM.

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