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!feeder.eternal-september.org!news.glorb.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Date: Mon, 06 Jul 2015 11:13:17 +0000 From: Matthias-Christian Ott User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Dynamic allocation in the predefined language environment Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Message-ID: <559a623d$0$293$14726298@news.sunsite.dk> Organization: SunSITE.dk - Supporting Open source NNTP-Posting-Host: 149.222.160.108 X-Trace: news.sunsite.dk DXC=ZAdHD:^H6`IL?MA7T=6bbGYSB=nbEKnkKAD_Z5jPE\=A?QBB4OQc1?N9S2C>Lo?V]O;VN_gQ4ieB1SI X-Complaints-To: staff@sunsite.dk Xref: news.eternal-september.org comp.lang.ada:26631 Date: 2015-07-06T11:13:17+00:00 List-Id: 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. I looked at the implementation of unbounded-length strings in GNAT and it seems to be impossible to change to storage pool for unbounded-length strings because the Shared_String type is private. Moreover, I don't want depend on implementation details. At a certain point every complex embedded system that deals with user or network inputs has to use dynamic memory allocation and I can't imagine that not handling memory allocations errors in some way is an option for such systems. So there has to be a way to achieve what I want without writing larger parts of the predefined language environment yourself or relying on implementation details of a specific compiler. Even the C++ STL has some crippled way to use custom memory allocators for dynamic data structures and I thought Ada is able to handle memory allocation errors better than just crashing or terminating the program like some functional programming languages do. Has somebody encountered the same problem and perhaps solved it? Is there an alternative solution to the problem that I have not considered? - Matthias-Christian