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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5117b1b6391a0e06 X-Google-Attributes: gid103376,public Newsgroups: comp.lang.ada Subject: Re: A simple ADA puzzle (I haven't the answer) References: <_Q%zc.7117$Wr.4869@newsread1.news.pas.earthlink.net> <5ad0dd8a.0406181007.775eae12@posting.google.com> From: Brian May X-Home-Page: http://snoopy.apana.org.au/~bam/ Date: Sat, 19 Jun 2004 12:11:03 +1000 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:Et2qT/t1nkTKDROPVa+nWALQ48U= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: dsl-202-173-153-89.vic.westnet.com.au X-Trace: news.melbourne.pipenetworks.com 1087611063 202.173.153.89 (19 Jun 2004 12:11:03 +1000) X-Complaints-To: abuse@pipenetworks.com X-Abuse-Info: Please forward all headers to enable your complaint to be properly processed. Path: g2news1.google.com!news1.google.com!news.glorb.com!news.moat.net!border1.nntp.sjc.giganews.com!border2.nntp.sjc.giganews.com!nntp.giganews.com!news1.optus.net.au!optus!news.mel.connect.com.au!news.melbourne.pipenetworks.com!not-for-mail Xref: g2news1.google.com comp.lang.ada:1679 Date: 2004-06-19T12:11:03+10:00 List-Id: >>>>> "Frank" == Frank J Lhota writes: Frank> The answer depends heavily on how Unbounded_String is Frank> implemented, and that will vary from compiler to Frank> compiler. However, I think I know what point you're getting Frank> at: the Unbounded_String solution has its own storage Frank> overhead, and that if the strings involved are all short Frank> enough, the Unbounded_String approach may actually use more Frank> memory. This is an issue where there is a tradeoff between efficiency of the program and how general it can be. (note: when I say "you" read as "the programmer or the interpreter/compiler"). If you want fixed length strings, then you are stuck with a fixed length, but you get maximum use of memory, and minimal overheads. If you want variable length strings, but have a maximum length, you can allocate up to this maximum length, but you need to keep track of the actual length used somehow, eg. by counting bytes or adding a null terminator at the end of the string. Also if you accidently exceed this length, you will get undesired results (unless you are using Ada and can somehow gracefully deal with the exception). If you want variable length strings, with no maximum limit, then you need to allocate/free memory dynamically at run time and keep track of the length allocated. Some languages may try to hide these issues (to various degrees) from the programmers, but they still remain issues which may be important with some applications (eg. time critical applications). At least Ada not only allows you to choose which one you want (like C or C++), but it will also enforce your choice to, so you can't exceed the maximum length for instance and allow corrupting surrounding data. Similar issues also arise with arrays. -- Brian May