comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jeffrey.carter@boeing.com>
Subject: Re: To_Unbounded_String and PROGRAM_ERROR
Date: Fri, 1 Feb 2002 16:38:33 GMT
Date: 2002-02-01T16:38:33+00:00	[thread overview]
Message-ID: <3C5AC489.70CCB3F1@boeing.com> (raw)
In-Reply-To: pan.2002.02.01.12.06.41.213262.3637@zamek.gda.pl

Michal Nowikowski wrote:
> 
> ---
> Path : array(1..1500) of Unbounded_String;
> ...
> for I in 1..1500 loop
>         Path(I) := To_Unbounded_String(Get_Current_Dir & Some_String);
> end loop;
> ---
> 
> and get sth like that
> raised PROGRAM_ERROR : a-strunb.ads:368
> 
> This occure after few iterations - it depends of length of converted
> string. It looks for me that the limmit of memory is exceeded.
> Have You any idea how to cope with it?

What platform and compiler? This looks like a GNAT message; in GNAT,
stack checking is off by default. Read the documentation for information
about turning it on. That might give you more information.

Part of the problem may be that every iteration performs the
concatenation (may create a temporary), conversion to Unbounded_String
(may create a temporary), and assignment (which probably performs
finalization). Since the string appears to be constant, something like

Path_Value : constant Unbounded_String := To_Unbounded_String (...);
...
Path := (others => Path_Value);

might be better.

Another possibility is

type Path_List is array (1 .. 1_500) of Unbounded_String;

Path : Path_List := (others => Path_Value);

which should eliminate many temporaries and the finalization, since this
is an initialization, not an assignment, or

Initial_Path : constant Path_List := (others => Path_Value);

Path : Path_List := Initial_Path;

though this might double the memory usage.

Note that it is generally considered better to say

for I in Path'range

than to repeat the magic numbers 1 and 1_500.

-- 
Jeffrey Carter



      parent reply	other threads:[~2002-02-01 16:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-01 11:06 To_Unbounded_String and PROGRAM_ERROR Michal Nowikowski
2002-02-01 12:34 ` Michal Nowak
2002-02-01 14:02 ` Preben Randhol
2002-02-01 16:11 ` Ted Dennison
2002-02-11  9:53   ` Michal Nowikowski
2002-02-14  0:32     ` Nick Roberts
2002-02-01 16:38 ` Jeffrey Carter [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