comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: problems parse (large) json file with gnatcoll.json
Date: Tue, 19 Apr 2016 14:49:28 +0200
Date: 2016-04-19T14:49:28+02:00	[thread overview]
Message-ID: <nf59ae$sk9$1@dont-email.me> (raw)
In-Reply-To: <5b61bc14-bda1-4ade-ac0c-5b5531b72d7e@googlegroups.com>

On 19.04.16 11:56, gautier_niouzes@hotmail.com wrote:
> Alternatively to the access type option, you can use an Unbounded_String; then the heap allocation *and* deallocation is done for you behind the scenes.

It was sad, though, when the makers of GCC/GNAT had
started to make Ada programs subject to unforeseeable stack
size implications that would make pretty normal programs
raise Storage_Error in an unpredictable way. As is frequently
the case, "good reasons" were stated for giving up plain
old arrays in favor of explicit memory management, or for
suggesting the use of more complex data structures; IIRC,
this has to do with implementation decisions in the C
compiler market in order to attack problems at that level
of implementation.

For example, the function below uses an array of
dynamic size, and will raise at some point depending
on the value of Size at run-time:

    function Using_Local_String (Size : Positive) return Boolean
    is
       subtype S is String (1 .. Size);
       X : S;
    begin
       X (X'First) := Character'Max('A', X (X'Last));
       return X (X'First) = 'A';
    end Using_Local_String;

Try approximating the "Bang!" size:

    for N in 1 .. 24 loop
       X := Big_String.Using_Local_String (Size => 2**N);
       Text_Io.Put_Line
         (Item => Positive'Image(2**N) & " -> " & Boolean'Image (X));
    end loop;

Mine is here:
   4194304 -> TRUE

raised STORAGE_ERROR : stack overflow



      reply	other threads:[~2016-04-19 12:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-18 18:21 problems parse (large) json file with gnatcoll.json Björn Lundin
2016-04-18 18:51 ` Jeffrey R. Carter
2016-04-18 19:05   ` Björn Lundin
2016-04-19 19:48     ` Shark8
2016-04-20  7:50       ` AdaMagica
2016-04-21  8:44       ` Björn Lundin
2016-04-25 10:38     ` briot.emmanuel
2016-04-25 15:12       ` Björn Lundin
2016-04-18 18:59 ` joakimds
2016-04-18 19:23   ` Björn Lundin
2016-04-19  8:17 ` Jacob Sparre Andersen
2016-04-19  9:14   ` Björn Lundin
2016-04-19  9:56 ` gautier_niouzes
2016-04-19 12:49   ` G.B. [this message]
replies disabled

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