From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bed2755a22ee69a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 22 Feb 2007 22:54:19 -0600 From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Text Processing in Ada 95 Date: Thu, 22 Feb 2007 20:55:30 -0800 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original Message-ID: NNTP-Posting-Host: 24.20.111.245 X-Trace: sv3-0mnJbAD5wBgqsKrxH/PLeosn/5+p/jMDYGmzEQpxST5K1nLv1R6Nad7/UNjrcQmSDENRieWQON7epT3!p0r4AZGN1GPLz83aHHrpMUwJwlfHinmfS5o9x4ST23Qd8uc4TKUTM7F6DSfrnbfmIJFtIdaZ6Iid!bsEqDvNzKnAysQ== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:9441 Date: 2007-02-22T20:55:30-08:00 List-Id: "Rob Norris" 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.