comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: When to use Bounded_String?
Date: Sun, 19 Nov 2017 11:55:59 +0200
Date: 2017-11-19T11:55:59+02:00	[thread overview]
Message-ID: <f7d2pfFctulU1@mid.individual.net> (raw)
In-Reply-To: <ouqpnm$a2j$1@gioia.aioe.org>

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
       .      @       .


  reply	other threads:[~2017-11-19  9:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-19  2:19 When to use Bounded_String? Victor Porton
2017-11-19  9:55 ` Niklas Holsti [this message]
2017-11-20  5:38   ` J-P. Rosen
2017-11-20  7:32     ` Niklas Holsti
2017-11-23 10:04 ` briot.emmanuel
2017-12-28 11:46   ` Vincent DIEMUNSCH
2017-12-28 12:00     ` Dmitry A. Kazakov
2017-12-28 12:29       ` Mehdi Saada
2017-12-29  0:42         ` Randy Brukardt
2017-12-29  9:11         ` Simon Wright
2017-12-28 14:28       ` vincent.diemunsch
2017-12-29  0:36         ` Randy Brukardt
2017-12-29  8:48           ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox