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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c32f6f0b23106020 X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: Large strings in ADA Date: 2000/04/17 Message-ID: #1/1 X-Deja-AN: 612069384 References: X-Complaints-To: abuse@pacbell.net X-Trace: news.pacbell.net 955940008 207.214.211.159 (Sun, 16 Apr 2000 19:53:28 PDT) Organization: SBC Internet Services NNTP-Posting-Date: Sun, 16 Apr 2000 19:53:28 PDT Newsgroups: comp.lang.ada Date: 2000-04-17T00:00:00+00:00 List-Id: >Perhaps you should try duplicating the -exact- C semantics. Presumably >you have a -very- large char buffer into which the items are copied. If the original is in C, it must have something like char Msg[2500000]; // 2.5 MB so the straightforward Ada equivalent would be Msg : String(1 .. 2_500_000); -- 2.5 MB If Appends are about K characters that will be 2.5E6/K Appends. If Append is done with strcat, searching for the terminating null instead of by maintaining an index, the total amount of scanning would be 0+K+2K+3K ... 25.E6 or nearly K*(2.5E6/K)**2/2 or 3E12/K. If the machine can scan for a null at a 10**9 byte/sec, and that's the only thing that takes any time at all, then K, the average string length, must be at least 3,000. Assuming the average string length is substantially less than 3K characters, we see that the C version must be using an index. In that case the simple Ada equivalent would be something like: Msg : String(1 .. 2_500_000); Last : Natural := 0; procedure Append_To_Msg (Str : in String; Max_Len : in Natural; Message : in out String; Last : in out Natural) is New_Stuff : constant String := " " & Natural'Image(Max_Len) & " " & Str; begin Message(Last+1 .. Last+New_Stuff'length) := New_Stuff; Last := Last + New_Stuff'length; end Add_To_Message; I made that change, modified the given program to compilable Ada, changed the loop from 1 .. 1600 to 1 .. 2_500_000/(32+4) (each append stores 36 characters), compiled with gnat 3.12p NT with -O2 -gnato, and the result runs on a Pentium 200 in 0.8 second.