From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Text Processing in Ada 95
Date: Thu, 22 Feb 2007 20:55:30 -0800
Date: 2007-02-22T20:55:30-08:00 [thread overview]
Message-ID: <N_OdnWDOLKHm7kPYnZ2dnUVZ_segnZ2d@comcast.com> (raw)
In-Reply-To: l22pt2114r910becfeg00e1dl1vb7flesq@4ax.com
"Rob Norris" <firstname.lastname@baesystems.com> wrote in message
news:l22pt2114r910becfeg00e1dl1vb7flesq@4ax.com...
>
> Suppose I have a text file such as:
>
> tom
> dick
> harry
>
> Then I want to insert the line "dave" after tom so the file is
>
> tom
> dave
> dick
> harry
>
> Also suppose text file can get rather large.
>
> Currently I'm using text_io which means I have to copy the whole thing
> into memory, insert the line
> then over write the file with new contents. direct_io is not an option
> (varing string lengths)
Actually Direct_IO is an option, and probably the fastest way to handle the
operation.
Step 1. Determine the initial file size
Step 2. Allocate a buffer that is the size of the file plus the size of
the string you want to add (including a line terminator)
Step 3. Create an instance Direct_IO that is the file size
Step 5. Read the file into the start of the allocated buffer in one gulp
Step 6. Insert your string in the buffer (a little tricky, but doable)
Step 7. Create an instance of Direct_IO that is the size of the buffer
with the new string
Step 8. Write the buffer to a file as one operation.
It's kind of messy to deal with the content of a text file in a buffer, and
will not work on systems with structured files (like VMS) but will work on
most modern systems.
Regards,
Steve
(The Duck)
>
> What alternatives should I consider for making insertions faster?
> (NB retrieval of a line needs to be fairly quick as well).
>
> Thanks in advance.
next prev parent reply other threads:[~2007-02-23 4:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-21 18:09 Text Processing in Ada 95 Rob Norris
2007-02-21 19:07 ` Pascal Obry
2007-02-22 14:02 ` Larry Kilgallen
2007-02-21 20:16 ` Randy Brukardt
2007-02-22 2:45 ` Jeffrey R. Carter
2007-02-22 11:56 ` Rob Norris
2007-02-23 4:30 ` Jeffrey R. Carter
2007-02-23 13:51 ` Stephen Leake
2007-02-26 12:11 ` Rob Norris
2007-02-23 4:55 ` Steve [this message]
2007-02-23 5:19 ` Randy Brukardt
2007-02-23 7:53 ` Jacob Sparre Andersen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox