comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: implementation question about writing and reading from files
Date: Fri, 10 Aug 2001 00:55:02 GMT
Date: 2001-08-10T00:55:02+00:00	[thread overview]
Message-ID: <GhGc7.47557$Kd7.27678338@news1.rdc1.sfba.home.com> (raw)
In-Reply-To: 9kv5rs$6hosn$2@ID-102190.news.dfncis.de

>the parameters mean...obviously File_Type is the file i'm getting, but what
>about the Item and Last parameters?  Is Stream_Element a generic type I have
>to declare, and if so, how and where do I do that?  If not, how can I ensure
>I'm getting the amount of data out of the file that I want on any platform?
>
>The From param in Read - what does this represent exactly?  from byte #?
>from Stream_Element # in the stream?
  You need a book, or look at www.adapower.com for the Ada 95 Reference
Manual (ARM).  A.12.1(31) says "The position of the first element in the
file is 1."  The Ada.Streams.Stream_IO Read and Write operate with
Stream_Element_Array's, which are defined in Ada.Streams, where ARM
13.13.1(4) says
  type Stream_Element is mod (implementation defined);
Probably a Stream_Element is a single byte, but there are weird systems
where it might be a 20 bit word or something.  Check your compiler's docs.

>How do i instantiate a stream that I can just write to and read from
>at my leisure?
  You can certainly do Ada.Streams.Stream_IO Read and Write at your
leisure.  There's nothing to instantiate, just use it.  It's even
simpler than Text/Sequential/Direct_IO.

>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?
  Ada.Streams.Stream_IO.Read/Write ought to be fast.  They don't do
any formatting or buffering or anything, just straightforward byte
(actually Stream_Element_Array) IO.  If you Declare
  Glob : Ada.Streams.Stream_Element_Array(1 .. 1_000_000);
you can read or write the whole thing in one call.

>And also, if I want to use a stream for keeping data in memory, how do i
>that?
  Not with Ada.Streams.Stream_IO.  There is something else entirely,
Ada.Streams, that handles automatically reading and writing everything
from a boolean to an array of tagged records.  It doesn't actually do
any IO - it just handles converting things to and from byte streams
(well, actually Stream_Element_Arrays) and calls your routine to do
the actual IO.  If you want to move things in memory, have your
routine do that, and not do any IO.

What is the level of abstraction here?  If you aren't looking at the
contents of the data, but just shoving it around, use
Ada.Streams.Stream_IO.  If you are looking at is as structured
information that you want to pay attention to, then use Ada.Streams
as well, or even use Ada.Direct_IO if it's just a series of fixed
size records.



  reply	other threads:[~2001-08-10  0:55 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 [this message]
2001-08-10 14:49     ` Ted Dennison
2001-08-10 15:44       ` Warren W. Gay VE3WWG
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