comp.lang.ada
 help / color / mirror / Atom feed
* very long string and Segmentation fault
@ 2006-07-07  8:39 zychp
  2006-07-07 18:24 ` Martin Krischik
  2006-07-11  9:29 ` zychp
  0 siblings, 2 replies; 6+ messages in thread
From: zychp @ 2006-07-07  8:39 UTC (permalink / raw)


Hello,

I have problem with creating very long strings. When I try to create
string bigger than 5MB I get  Segmentation fault.

Tmp: String_Access;
...
Tmp := new String (1 .. 10_000_000);

In this line a get  Segmentation fault. I use GNAT 3.4.5.

What is more when I run this code:

   type ttt is array (positive range <> ) of Character;
   type ttt_a is access ttt;
   Tmp : ttt_a ;
begin
   Tmp := new ttt ( 1 .. 10_000_000 ) ;
   for i in Tmp'range loop
      Tmp(i) := 'x';
   end loop;

It works fine. But now it's hard to use some Ada.Strings.Fixed
functions.

What can be the reason of this? How it can be soved?

Regards
    Gorion

P.S. I have to use pure Strings (no Unbounded_String etc. ).




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

* Re: very long string and Segmentation fault
  2006-07-07  8:39 very long string and Segmentation fault zychp
@ 2006-07-07 18:24 ` Martin Krischik
  2006-07-07 19:17   ` Dr. Adrian Wrigley
  2006-07-11  9:29 ` zychp
  1 sibling, 1 reply; 6+ messages in thread
From: Martin Krischik @ 2006-07-07 18:24 UTC (permalink / raw)


zychp@o2.pl wrote:

> I have problem with creating very long strings. When I try to create
> string bigger than 5MB I get  Segmentation fault.

Well, you should not ;-)  - its certainly a compiler bug.

> Tmp: String_Access;
> ...
> Tmp := new String (1 .. 10_000_000);
> 
> In this line a get  Segmentation fault. I use GNAT 3.4.5.

Provided by whom?

> What is more when I run this code:
> 
>    type ttt is array (positive range <> ) of Character;
>    type ttt_a is access ttt;
>    Tmp : ttt_a ;
> begin
>    Tmp := new ttt ( 1 .. 10_000_000 ) ;
>    for i in Tmp'range loop
>       Tmp(i) := 'x';
>    end loop;
> 
> It works fine. But now it's hard to use some Ada.Strings.Fixed
> functions.
> 
> What can be the reason of this? How it can be soved?

As I said: Certainly a compiler bug so the solution can only be an upgrade.
You might want to have a look at:

http://gnuada.sf.net.

Mind you: There *might* be a new release for SuSE within the week.

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



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

* Re: very long string and Segmentation fault
  2006-07-07 18:24 ` Martin Krischik
@ 2006-07-07 19:17   ` Dr. Adrian Wrigley
  2006-07-07 19:38     ` Dmitry A. Kazakov
  2006-07-08  5:01     ` Martin Krischik
  0 siblings, 2 replies; 6+ messages in thread
From: Dr. Adrian Wrigley @ 2006-07-07 19:17 UTC (permalink / raw)


On Fri, 07 Jul 2006 20:24:52 +0200, Martin Krischik wrote:

> zychp@o2.pl wrote:
> 
>> I have problem with creating very long strings. When I try to create
>> string bigger than 5MB I get  Segmentation fault.
> 
> Well, you should not ;-)  - its certainly a compiler bug.

Actually, I think it is more of a feature(?)

I first hit this with GNAT 3.15p (Linux).  I think the explanation
was that the "new" was allocated on the stack when the data weren't
being kept after the function returns.  It's called "optimization",
apparently.  I had to resort to various tricks to get it to use
heap allocation instead. (making the size non-static might help.
Calling malloc instead works.)  Very messy. 
--
Adrian




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

* Re: very long string and Segmentation fault
  2006-07-07 19:17   ` Dr. Adrian Wrigley
@ 2006-07-07 19:38     ` Dmitry A. Kazakov
  2006-07-08  5:01     ` Martin Krischik
  1 sibling, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2006-07-07 19:38 UTC (permalink / raw)


On Fri, 07 Jul 2006 19:17:16 GMT, Dr. Adrian Wrigley wrote:

> On Fri, 07 Jul 2006 20:24:52 +0200, Martin Krischik wrote:
> 
>> zychp@o2.pl wrote:
>> 
>>> I have problem with creating very long strings. When I try to create
>>> string bigger than 5MB I get  Segmentation fault.
>> 
>> Well, you should not ;-)  - its certainly a compiler bug.
> 
> Actually, I think it is more of a feature(?)
> 
> I first hit this with GNAT 3.15p (Linux).  I think the explanation
> was that the "new" was allocated on the stack when the data weren't
> being kept after the function returns.  It's called "optimization",
> apparently.  I had to resort to various tricks to get it to use
> heap allocation instead. (making the size non-static might help.
> Calling malloc instead works.)  Very messy.

Hmm, and the pointer wasn't "access all?" I mean, if the pointer were
pool-specific, then GNAT wouldn't have right to do such optimization. Then,
[if that doesn't help] it is quite straightforward to write a storage pool
with Allocate sucking memory from the heap. 

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: very long string and Segmentation fault
  2006-07-07 19:17   ` Dr. Adrian Wrigley
  2006-07-07 19:38     ` Dmitry A. Kazakov
@ 2006-07-08  5:01     ` Martin Krischik
  1 sibling, 0 replies; 6+ messages in thread
From: Martin Krischik @ 2006-07-08  5:01 UTC (permalink / raw)


Dr. Adrian Wrigley wrote:

> On Fri, 07 Jul 2006 20:24:52 +0200, Martin Krischik wrote:
> 
>> zychp@o2.pl wrote:
>> 
>>> I have problem with creating very long strings. When I try to create
>>> string bigger than 5MB I get  Segmentation fault.
>> 
>> Well, you should not ;-)  - its certainly a compiler bug.
> 
> Actually, I think it is more of a feature(?)
> 
> I first hit this with GNAT 3.15p (Linux).  I think the explanation
> was that the "new" was allocated on the stack when the data weren't
> being kept after the function returns.  It's called "optimization",
> apparently.  I had to resort to various tricks to get it to use
> heap allocation instead. (making the size non-static might help.
> Calling malloc instead works.)  Very messy.

Library Level access type ???

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



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

* Re: very long string and Segmentation fault
  2006-07-07  8:39 very long string and Segmentation fault zychp
  2006-07-07 18:24 ` Martin Krischik
@ 2006-07-11  9:29 ` zychp
  1 sibling, 0 replies; 6+ messages in thread
From: zychp @ 2006-07-11  9:29 UTC (permalink / raw)



> What can be the reason of this? How it can be soved?
The problem was because of pragma Initialize_Scalars added to whole
project.
Now it's working fine.

Thx for answers




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

end of thread, other threads:[~2006-07-11  9:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-07  8:39 very long string and Segmentation fault zychp
2006-07-07 18:24 ` Martin Krischik
2006-07-07 19:17   ` Dr. Adrian Wrigley
2006-07-07 19:38     ` Dmitry A. Kazakov
2006-07-08  5:01     ` Martin Krischik
2006-07-11  9:29 ` zychp

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