comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Passing indefinite types
Date: Mon, 4 Feb 2013 20:40:24 -0600
Date: 2013-02-04T20:40:24-06:00	[thread overview]
Message-ID: <keprer$b9r$1@munin.nbi.dk> (raw)
In-Reply-To: 8d39b2ad-dc6c-4492-bc43-d2d01d748efa@googlegroups.com

<sbelmont700@gmail.com> wrote in message 
news:8d39b2ad-dc6c-4492-bc43-d2d01d748efa@googlegroups.com...
On Sunday, February 3, 2013 5:26:15 PM UTC-5, Stephen Leake wrote:
>>
>> Could you show some almost legal code?
>
>I have found several occasions where this is useful (mostly for dealing 
>with classwide types
>in constructing functions), but for an example consider something more 
>straightforward:
>Suppose you want to write a subprogram that searches for a string pattern 
>within an
>unconstrained number of other strings (and also suppose for the sake of 
>argument that
>you cannot implement it as multiple calls to a subprogram that searches 
>within a single string).

For this particular example, you ought to use an array of unbounded strings 
(or, if heap use has to be completely avoided, an array of bounded strings). 
QED. :-)

The clear analog of this is either an array of holder containers, or a 
vector of indefinite items. I realize both of these use the heap, but really 
that shouldn't be a concern until/unless it is proven to be an issue. 
(Trying to avoid it initially is almost always premature optimization.)

It hard to imagine doing too much with indefinite objects without resorting 
to the heap (or containers that use the heap) at some point. That's true for 
not just this problem, but pretty much any problem. The main reason to avoid 
heap use is worries about botched memory management, but that shouldn't be a 
concern if you use a predefined container or type like unbounded strings. If 
you truly need to avoid the heap (as per some embedded systems), I suspect 
you'll be forced to avoid indefinite types, too (other than as parameters as 
in class-wide or unconstrained array parameters).

Just my 5 cents.

                            Randy.





  parent reply	other threads:[~2013-02-05  2:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-02 21:07 Passing indefinite types sbelmont700
2013-02-02 21:31 ` Jeffrey Carter
2013-02-03  0:27   ` sbelmont700
2013-02-03  8:07     ` Dmitry A. Kazakov
2013-02-03 10:22 ` gautier_niouzes
2013-02-03 22:26 ` Stephen Leake
2013-02-04  1:25   ` sbelmont700
2013-02-04  3:46     ` Shark8
2013-02-05  2:40     ` Randy Brukardt [this message]
2013-02-05 13:01     ` Stephen Leake
2013-02-05 20:56       ` Randy Brukardt
2013-02-05 21:16 ` sbelmont700
replies disabled

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