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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c01667c07f51ded5 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.3) Gecko/20040910 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Advanced file manipulation (multiple question) References: <74a78c42.0503010130.785f178f@posting.google.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Wed, 02 Mar 2005 16:56:16 GMT NNTP-Posting-Host: 4.254.200.240 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1109782576 4.254.200.240 (Wed, 02 Mar 2005 08:56:16 PST) NNTP-Posting-Date: Wed, 02 Mar 2005 08:56:16 PST Xref: g2news1.google.com comp.lang.ada:8587 Date: 2005-03-02T16:56:16+00:00 List-Id: Steve wrote: > If you use Ada.Direct_Io, there is a nice way to read the file in one read, > but it takes two steps. > First create an instance of Ada.Direct_Io of bytes. > Open the file as bytes. System.Storage_Elements.Storage_Element. > Use the size function to get the size of the file. > Close the file > Create an instance of Ada.Direct_IO with an element that is the size of > the file (an array of bytes maybe?). System.Storage_Elements.Storage_Array. > Read the file (a single read) > Close the file. > > This approach tends to be quite fast since there is no iteration involved > over the bytes of the file. Right, but this is limited to files that will fit in memory. The streams approach I described using varying-size chunks will work for all files, and is equivalent to this approach for smaller files. In addition, it does not require opening the file twice. -- Jeff Carter "What I wouldn't give for a large sock with horse manure in it." Annie Hall 42