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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: When to use Bounded_String? Date: Sun, 19 Nov 2017 11:55:59 +0200 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Ae9AOoPo73Lyl48XRF6snAueUIN4EYU9I1F03xBB2QC89RAqj2 Cancel-Lock: sha1:tf+kdY10giBWmrcwAHXOxGQTaaM= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: feeder.eternal-september.org comp.lang.ada:49001 Date: 2017-11-19T11:55:59+02:00 List-Id: On 17-11-19 04:19 , Victor Porton wrote: > Is it worth to use Bounded_String for short strings (which are expected to > be say 12 chars max, as a program version string)? or is Unbounded_String > fast enough and this a preliminary optimization? What is "fast enough" depends on your application and your Ada implementation. If you worry about it, make some measurements. > Also not using Bounded_String at all may shorten the program code, right? By leaving out the code for the Bounded_String instances, you mean? Yes, but for any significant application the reduction in code size is probably very fractional, unless you make very many different instances of Bounded_Strings (and your Ada implementation does not share code between instances). > What is the main purpose of Bounded_String? As I understand it, the purpose is to let a program use string variables of dynamically varying length, without using dynamically allocated heap memory. The penalty is a fixed upper bound on the length, and perhaps more copying of characters from one variable to another (depending on the implementation). However, the avoidance of heap is only Implementation Advice (RM A.4.4(106)) so you should check what your Ada implementation does, if avoiding heap is important to you. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .