|
From: Pascal Obry on 21 Feb 2007 14:07 Rob Norris a �crit : > 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) Use Text_IO ok, but why copy all in memory. Just write to a temp file, delete the original one and rename the temp file. > What alternatives should I consider for making insertions faster? > (NB retrieval of a line needs to be fairly quick as well). If you have a lot of modifications to do on the file, then you probably need to read all the file in memory to have good performances. In this case, read file in blocks using Stream_IO. Do the changes in memory and write it back in blocks using Stream_IO. Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
From: Randy Brukardt on 21 Feb 2007 15:16 Rob Norris writes: .... > 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) > > What alternatives should I consider for making insertions faster? > (NB retrieval of a line needs to be fairly quick as well). An insertion into a file requires that you're going to have to rewrite everything after the insertion anyway. So there isn't any way to do that cheaply if you have to do it one insertion at a time. Thus my recommendation is to not do it - that is, find a better way to accomplish whatever it is you need to do. For instance, create a file listing the insertions as an adjunct to the original file, and do the merge only on rare occassions. That would allow copying the file only rarely, and allows doing a large number of insertions at once. If you absolutely have do this as you described, Pascal Obry's suggestions are probably the best. My Trash Finder spam filter has to do this to add header lines to stored messages, and it uses Stream_IO to read and write the file (that can be much cheaper than using Text_IO, because it does not need to look for the ends of lines once it has determined the insertion point). Randy.
From: Jeffrey R. Carter on 21 Feb 2007 21:45 Rob Norris wrote: > > 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) Is there an upper limit to the string lengths (other than Positive'Last)? If so, you could use Ada.Strings.Bounded and Direct_IO. -- Jeff Carter "You tiny-brained wipers of other people's bottoms!" Monty Python & the Holy Grail 18
From: Rob Norris on 22 Feb 2007 06:56 On Wed, 21 Feb 2007 18:09:09 +0000, Rob Norris <firstname.lastname(a)baesystems.com> wrote: > >Suppose I have a text file such as: > <cut> Thanks everyone for the input. I suspected as much that I would have to do some stream_io. Unfortunately I can't do things any other way. The requirement is for a text file :( I may investigate bounded string option as mentioned by Jeffrey C.
From: Larry Kilgallen on 22 Feb 2007 09:02
In article <45DC988E.7040800(a)obry.net>, Pascal Obry <pascal(a)obry.net> writes: > Rob Norris a �crit : >> 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) > > Use Text_IO ok, but why copy all in memory. Just write to a temp file, > delete the original one and rename the temp file. > >> What alternatives should I consider for making insertions faster? >> (NB retrieval of a line needs to be fairly quick as well). > > If you have a lot of modifications to do on the file, then you probably > need to read all the file in memory to have good performances. In this > case, read file in blocks using Stream_IO. Do the changes in memory and > write it back in blocks using Stream_IO. Or use an operating system feature that allows insertions. GNAT Ada 95 on VMS is supposed to emulate DEC Ada features, so that should include the Mixed_Indexed_IO package. There will be more overhead in disk files but for large files it is much better for inserting data in the middle. |