comp.lang.ada
 help / color / mirror / Atom feed
* Dynamic allocation in the predefined language environment
@ 2015-07-06 11:13 Matthias-Christian Ott
  2015-07-06 13:04 ` G.B.
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Matthias-Christian Ott @ 2015-07-06 11:13 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2015-07-10 21:58 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-06 11:13 Dynamic allocation in the predefined language environment Matthias-Christian Ott
2015-07-06 13:04 ` G.B.
2015-07-06 14:21   ` Matthias-Christian Ott
2015-07-06 14:06 ` Bob Duff
2015-07-06 14:16   ` Matthias-Christian Ott
2015-07-06 14:23     ` G.B.
2015-07-06 14:43       ` Matthias-Christian Ott
2015-07-06 14:56         ` Bob Duff
2015-07-07  8:46           ` Matthias-Christian Ott
2015-07-07 22:32             ` Bob Duff
2015-07-08 19:47               ` Randy Brukardt
2015-07-08 21:08                 ` Bob Duff
2015-07-10 21:58                   ` Randy Brukardt
2015-07-08 21:16                 ` Dmitry A. Kazakov
2015-07-06 14:45     ` Bob Duff
2015-07-06 20:28       ` Randy Brukardt
2015-07-07  8:49       ` Matthias-Christian Ott
2015-07-07 22:14         ` Bob Duff
2015-07-06 15:29   ` Simon Wright
2015-07-06 20:31     ` Randy Brukardt
2015-07-06 21:35       ` Simon Wright
2015-07-07 18:29         ` Randy Brukardt
2015-07-06 20:22   ` Randy Brukardt
2015-07-06 18:45 ` Jeffrey R. Carter
2015-07-07  7:42 ` Dmitry A. Kazakov
2015-07-07  8:23   ` Matthias-Christian Ott
2015-07-07  8:46     ` Dmitry A. Kazakov

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