comp.lang.ada
 help / color / mirror / Atom feed
* To_Unbounded_String and PROGRAM_ERROR
@ 2002-02-01 11:06 Michal Nowikowski
  2002-02-01 12:34 ` Michal Nowak
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Michal Nowikowski @ 2002-02-01 11:06 UTC (permalink / raw)


Hello

I've this code:

---
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?

Best Regards
Godfryd

-- 
|  Michal Nowikowski <godfryd@zamek.gda.pl>
|  wym�wka admina #348:
|  We're on Token Ring, and it looks like the token got loose.



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

* Re: To_Unbounded_String and PROGRAM_ERROR
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Michal Nowak @ 2002-02-01 12:34 UTC (permalink / raw)


On 02-02-01 at 12:06 Michal Nowikowski wrote:

>Hello
>
>I've this code:
>
>---
>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?

You may handle an exception. But I suppose this is not the kind of answer
you want. 
You may also try to estimate the maximum lenght of string you want to
store and do something like this:
Path : array(1..1500) of String (1 .. Max_Length);
If you are really low on memory, this won't run also.
But, if this work, maybe not the lack of memory is the problem.
Maybe there is something in Get_Current_Dir function?

Hope this gave some help,
Mike:
-----------------------------------------
                             ____|
                             \%/ |~~\
  O                                  |
 o>>        Mike Nowak               |
 T                                   |
/ >       vinnie@inetia.pl           |
http://www.geocities.com/vinnie14pl _|__




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

* Re: To_Unbounded_String and PROGRAM_ERROR
  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-01 16:38 ` Jeffrey Carter
  3 siblings, 0 replies; 7+ messages in thread
From: Preben Randhol @ 2002-02-01 14:02 UTC (permalink / raw)


On Fri, 01 Feb 2002 12:06:42 +0100, Michal Nowikowski wrote:
> Hello
> 
> I've this code:
> 
> ---
> 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?

add the compiler option -fstack-check

and read : Stack Overflow Checking in the GNAT User Guide.

But do you really have 1500 paths?

-- 
Preben Randhol         �For me, Ada95 puts back the joy in programming.�



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

* Re: To_Unbounded_String and PROGRAM_ERROR
  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-01 16:38 ` Jeffrey Carter
  3 siblings, 1 reply; 7+ messages in thread
From: Ted Dennison @ 2002-02-01 16:11 UTC (permalink / raw)


Michal Nowikowski <godfryd@zamek.gda.pl> wrote in message news:<pan.2002.02.01.12.06.41.213262.3637@zamek.gda.pl>...

{code creating 1500 unbounded strings deleted}

> 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?

Can you come up with a rough estimate of how much memory this is
taking up, were it to complete?

Also, does this code happen to be in a task? Some compilers keep
separate heaps for each task, typically with a much smaller default
size than the main task gets.

-- 
T.E.D. 
Home     -  mailto:dennison@telepath.com (Yahoo: Ted_Dennison)
Homepage -  http://www.telepath.com/dennison/Ted/TED.html



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

* Re: To_Unbounded_String and PROGRAM_ERROR
  2002-02-01 11:06 To_Unbounded_String and PROGRAM_ERROR Michal Nowikowski
                   ` (2 preceding siblings ...)
  2002-02-01 16:11 ` Ted Dennison
@ 2002-02-01 16:38 ` Jeffrey Carter
  3 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2002-02-01 16:38 UTC (permalink / raw)


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



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

* Re: To_Unbounded_String and PROGRAM_ERROR
  2002-02-01 16:11 ` Ted Dennison
@ 2002-02-11  9:53   ` Michal Nowikowski
  2002-02-14  0:32     ` Nick Roberts
  0 siblings, 1 reply; 7+ messages in thread
From: Michal Nowikowski @ 2002-02-11  9:53 UTC (permalink / raw)


On Fri, 01 Feb 2002 17:11:02 +0100, Ted Dennison wrote:

> Also, does this code happen to be in a task? Some compilers keep
> separate heaps for each task, typically with a much smaller default size
> than the main task gets.

Now I see that it is problem with allocating memory.Can I expand
available memory or can I check how much free memory left. How can
I manage with limitation of dynamic allocation???

Godfryd

-- 
|  Michal Nowikowski <godfryd@zamek.gda.pl>
|  wym�wka admina #229:
|  wrong polarity of neutron flow



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

* Re: To_Unbounded_String and PROGRAM_ERROR
  2002-02-11  9:53   ` Michal Nowikowski
@ 2002-02-14  0:32     ` Nick Roberts
  0 siblings, 0 replies; 7+ messages in thread
From: Nick Roberts @ 2002-02-14  0:32 UTC (permalink / raw)


On Mon, 11 Feb 2002 10:53:42 +0100, Michal Nowikowski
<godfryd@zamek.gda.pl> strongly typed:

>On Fri, 01 Feb 2002 17:11:02 +0100, Ted Dennison wrote:
>
>> Also, does this code happen to be in a task? Some compilers keep
>> separate heaps for each task, typically with a much smaller default size
>> than the main task gets.
>
>Now I see that it is problem with allocating memory.Can I expand
>available memory or can I check how much free memory left. How can
>I manage with limitation of dynamic allocation???

I can give a little general advice.

See if you can change the program so that it uses less memory (but still
does its job properly). This is most likely to be the solution to your
problem.

Is your program running out of heap space (things allocated by 'new') or
stack space (everything else)? It might help to use less of one and more of
another.

How much RAM does your machine have? Check it is realistically enough. Does
your system provide virtual memory? Maybe it would help to enable this, or
to increase the amount.


-- 
Nick Roberts



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

end of thread, other threads:[~2002-02-14  0:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox