comp.lang.ada
 help / color / mirror / Atom feed
From: "Warren W. Gay VE3WWG" <ve3wwg@home.com>
Subject: Re: implementation question about writing and reading from files
Date: Fri, 10 Aug 2001 15:44:38 GMT
Date: 2001-08-10T15:44:38+00:00	[thread overview]
Message-ID: <3B74016F.CD240F7B@home.com> (raw)
In-Reply-To: rwSc7.5218$NJ6.24286@www.newsranger.com

Ted Dennison wrote:
> In article <9kv5rs$6hosn$2@ID-102190.news.dfncis.de>, Francis Crick says...
> >And also, if I want to use a stream for keeping data in memory, how do i
> >that?  How do i instantiate a stream that I can just write to and read from
> >at my leisure?
> 
> The only language-defined streams are in Ada.Streams.Stream_IO,
> Ada.Text_IO.Text_Streams, and Ada.Wide_Text_IO.Text_Streams. I believe they all
> deal with files. If you want to use one to make yourself a buffer, you will have
> to code it yourself by deriving it from Ada.Streams.Root_Stream_Type and
> overriding "Read" and "Write".

If you want a number of examples of streams code, download the AdaVox software
from: http://members.home.net/ve3wwg

I am currently re-vamping AdaVox, because there are a number of design problems
in it, but in the originally released code (see above), you will find
some code that implements a stream buffer. Look for file wc-streams-buffer.ads.

I am sure you can improve upon it, but it will get you started at least.

> 
> >               Also, the data I'm moving is large, and chances are I won't
> >be using it for much else other than writing back to other file streams, so
> >how can i make the reading and writing as fast as possible?  Could I make it
> >read a whole mb in one go as a single unit?
> 
> The easiest way to do that is to unchecked_conversion your data (or better yet,
> a pointer to it) into a Ada.Streams.Stream_Element_Array, then call
> Ada.Streams.Write directly. If you just use the stream attributes, it will
> perform one write for each element, which I've found to be significantly slower
> (even when the target is a memory-based stream).

I think the GNAT implementation is built upon the stdio (C) package, ultimately.
One way to improve performance some, is to increase the buffer size of the 
underlying "file". You'll need to look at the GNAT User Guide to find out how.
You will need to open a C file, and then turn it into an Ada stream.
Maybe someone else can volunteer the details here (I'm too pressed for
time to look it up).

This won't compensate for the procedure(attribute) calls (that Ted referred to), 
but it will make each I/O a larger one.

> A good Ada book should go over the basics of this. Stream use is a complicated
> enough topic that you really ought to have such a resource to learn the basics
> from.

Otherwise, be prepared to look at the streams specs a lot (as I did).
-- 
Warren W. Gay VE3WWG
http://members.home.net/ve3wwg



  reply	other threads:[~2001-08-10 15:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-05 22:18 implementation question about writing and reading from files Francis Crick
2001-08-05 22:43 ` tmoran
2001-08-09 23:19   ` Francis Crick
2001-08-10  0:55     ` tmoran
2001-08-10 14:49     ` Ted Dennison
2001-08-10 15:44       ` Warren W. Gay VE3WWG [this message]
2001-08-06 16:03 ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox