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!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Dynamic allocation in the predefined language environment Date: Mon, 06 Jul 2015 11:45:06 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <559a623d$0$293$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 6 Jul 2015 18:43:43 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="a3855fbfe1a666be9aefba0563039ed5"; logging-data="21299"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ATPTkiweEc4H1sXsQ0XficJqC5J7WxTI=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: <559a623d$0$293$14726298@news.sunsite.dk> Cancel-Lock: sha1:9UBQ7ztgkg8hpeQ07GxBlmrw9IU= Xref: news.eternal-september.org comp.lang.ada:26654 Date: 2015-07-06T11:45:06-07:00 List-Id: On 07/06/2015 04:13 AM, Matthias-Christian Ott wrote: > I need to store strings of unknown length. For security reasons I set > limits for the types of strings the software handles and I used > bounded-length strings to store them. However, it turned out that > bounded-length strings do not fit the use case very well because the > software sometimes has to convert between bounded-length strings of > various types which makes the code verbose and hard to read and more > importantly the limits are quite high so that I'm in trouble running out > of stack space. > > In order to avoid the limitations of bounded-length data structures I'm > currently looking for alternatives. > > Unbounded-length strings do not have this limitation but requires > dynamic memory allocation (or at least I see no other way to implement > it) which in turn requires error handling of memory allocation errors. > However, if I'm not mistaken neither Ada 95, nor Ada 2005, nor Ada 2012 > specify how memory allocation errors are to be reported or handled and > do not allow one to specify the storage pool from which unbounded-length > strings are allocated. The same seems to be true for other > unbounded/infinite data-structures. I suppose most implementations will > raise a Storage_Error exception but the standard does not specify how > the packages are to implemented so a program could simply crash and > would still conform to the standard. As Duff has pointed out, the language requires that Storage_Error be raised. Unbounded_String is essentially an instantiation of Vectors with Positive as the index type and Character as the element, with some added operations. As with all of the standard library, they are general purpose and may not be suitable where the S/W has specific needs. In this case, if knowing that Storage_Error will be raised doesn't help, you may need to create a version of variable-length strings that meets your requirements. -- Jeff Carter "It's symbolic of his struggle against reality." Monty Python's Life of Brian 78