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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9c86eb13dd395066 X-Google-Attributes: gid103376,public From: Tom Moran Subject: Re: CRC in Ada? Date: 1997/03/10 Message-ID: <33245B0A.3681@bix.com>#1/1 X-Deja-AN: 224461334 References: <1997Mar2.220652@nova.wright.edu> <1997Mar5.131846.1@eisner> <5fmo1k$adm@mulga.cs.mu.OZ.AU> <1997Mar6.114441.1@eisner> <1997Mar7.090814.1@eisner> <33206340.2616@bix.com> Organization: InterNex Information Services 1-800-595-3333 Reply-To: tmoran@bix.com Newsgroups: comp.lang.ada Date: 1997-03-10T00:00:00+00:00 List-Id: Robert Dewar says > This makes no sense at all. My best guess is that the business about > prime numbers is talking about trying to misuse direct_io to read the > file. > > The proper way to read this file in Ada 95 is to use Stream_IO into > a stream element buffer. The imagined "prime number" restriction > does not exist, and in practice this should be highly efficient. > > I am afraid this is just misinformation that comes from misunderstanding. > Yes, you did misunderstand. The original post implied that the comparison had taken place several years ago, which implies it was done in Ada 83, which did not implement Stream_IO. The only "strictly in Ada" way to read a file then was via Text, Sequential, or Direct_IO. Both Sequential and Direct_IO require fixed size records. (Not strictly true, but essentially true in practice. E.g., ActivAda, GNAT, and Janus will all accept a "(string)" as the parameter to Sequential_IO, but all three die on trying to actually read a text file in chunks that way.) So the fixed buffer size, if one did *not* use Text_IO, would have to be a divisor of the total file size. If the file size is a prime number, it's divisors are itself and one. One takes us back to the original byte-at-a-time that was 10x slower in Ada than C. If the whole file is small enough to fit in memory, then we could use a single fixed size record holding the entire file. If this doesn't fit in memory then that option is not available, and byte-at-a-time is the only way, strictly in Ada, to do the job. Yes, it can be done by calling the OS or a C function, and I'm sure everyone has done this. But it doesn't make Ada look particularly good to say "Oh yes, you can do it in Ada; just don't use the Ada IO packages".