comp.lang.ada
 help / color / mirror / Atom feed
* using 'storage_size ?
@ 2003-10-12  7:37 Alex Xela
  2003-10-12 12:34 ` Duncan Sands
  2003-10-12 23:24 ` Robert I. Eachus
  0 siblings, 2 replies; 7+ messages in thread
From: Alex Xela @ 2003-10-12  7:37 UTC (permalink / raw)


When the line 20 of the following code is uncommented the program raises a
Storage_Error with GNAT3.15p under W2k.

If I did not make a mistake, I reclaim for  5Mo at line 23. This is
confusing me?????



---------------

with ada.text_io,Unchecked_Deallocation,Ada.Exceptions;
procedure garbage is
   ko : constant := 1024;
   Mo : constant := ko*ko;
   type byte is range 0..255; for Byte'size use 8;
   type tab_byte is array(positive range <>) of byte; pragma pack(tab_byte);
   type ptr_Tab is access tab_byte;
   ptr1,ptr2 : ptr_tab;
   procedure free is new
Unchecked_Deallocation(Object=>tab_byte,name=>ptr_tab);
begin
   ada.text_io.put_line(" Garbage : begin ");
   for i in 1..10 loop
      ptr1 := new tab_byte'(positive'first..5*Mo=>255);
   end loop;
   ptr2 := new tab_byte'(positive'first..5*Mo=>255);
   ada.text_io.put_line("
  Ptr2.all'size ->"&integer'image(ptr2.all'size/(mo*8))&" Mo");
   ada.text_io.put_line("
  Ptr1.all'size ->"&integer'image(ptr1.all'size/(mo*8))&" Mo");
   declare
      type local_ptr is access tab_byte;
      for local_ptr'storage_size use Mo*8;--[line 20]GNAT 3.15p raised
STORAGE_ERROR : EXCEPTION_STACK_OVERFLOW
      ptr3 : local_ptr;
   begin
      ptr3 := new tab_byte'(positive'first..5*Mo=>255);--line 23
      ada.text_io.put_line("
  Ptr3.all'size ->"&integer'image(ptr3.all'size/(mo*8))&" Mo");
   end ;
   free(ptr1);
   free(ptr2);
   ada.text_io.put_line(" Garbage : end ");
end garbage;










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

* Re: using 'storage_size ?
  2003-10-12  7:37 using 'storage_size ? Alex Xela
@ 2003-10-12 12:34 ` Duncan Sands
  2003-10-12 14:12   ` Alex Xela
  2003-10-12 23:24 ` Robert I. Eachus
  1 sibling, 1 reply; 7+ messages in thread
From: Duncan Sands @ 2003-10-12 12:34 UTC (permalink / raw)
  To: Alex Xela, comp.lang.ada

On Sunday 12 October 2003 09:37, Alex Xela wrote:
> When the line 20 of the following code is uncommented the program raises a
> Storage_Error with GNAT3.15p under W2k.
>
> If I did not make a mistake, I reclaim for  5Mo at line 23. This is
> confusing me?????

It looks like the memory is being allocated on the stack.  On some machines the
stack is not allowed to be very big (or even if it is allowed to be big, you are
not allowed to increase its size too fast - this catches infinite recursive loops
and that kind of thing).

Duncan.



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

* Re: using 'storage_size ?
  2003-10-12 12:34 ` Duncan Sands
@ 2003-10-12 14:12   ` Alex Xela
  2003-10-12 18:23     ` Duncan Sands
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Xela @ 2003-10-12 14:12 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 931 bytes --]

--------------------------------------------

Yes, but why does it work when the line 20 is commented?
It is also working (with or without line 20) with the Aonix compiler
ObjectAda.
Alex.

--------------------------------------------
"Duncan Sands" <baldrick@free.fr> a �crit dans le message de news:
mailman.70.1065961988.25614.comp.lang.ada@ada-france.org...
> On Sunday 12 October 2003 09:37, Alex Xela wrote:
> > When the line 20 of the following code is uncommented the program raises
a
> > Storage_Error with GNAT3.15p under W2k.
> >
> > If I did not make a mistake, I reclaim for  5Mo at line 23. This is
> > confusing me?????
>
> It looks like the memory is being allocated on the stack.  On some
machines the
> stack is not allowed to be very big (or even if it is allowed to be big,
you are
> not allowed to increase its size too fast - this catches infinite
recursive loops
> and that kind of thing).
>
> Duncan.





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

* Re: using 'storage_size ?
  2003-10-12 14:12   ` Alex Xela
@ 2003-10-12 18:23     ` Duncan Sands
  0 siblings, 0 replies; 7+ messages in thread
From: Duncan Sands @ 2003-10-12 18:23 UTC (permalink / raw)
  To: Alex Xela, comp.lang.ada

> Yes, but why does it work when the line 20 is commented?
> It is also working (with or without line 20) with the Aonix compiler
> ObjectAda.

If you don't have line 20, standard storage will be used i.e. the heap.
This can handle much bigger sizes than the stack.  I guess ObjectAda
is not trying to allocate the storage pool on the stack (which sounds
very sensible of them).  I agree it is strange that the compiler does
this - and in fact maybe it doesn't, I'm only guessing it does.

Duncan.



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

* Re: using 'storage_size ?
  2003-10-12  7:37 using 'storage_size ? Alex Xela
  2003-10-12 12:34 ` Duncan Sands
@ 2003-10-12 23:24 ` Robert I. Eachus
  2003-10-13 18:20   ` Alex Xela
  1 sibling, 1 reply; 7+ messages in thread
From: Robert I. Eachus @ 2003-10-12 23:24 UTC (permalink / raw)


Alex Xela wrote:
> 
> with ada.text_io,Unchecked_Deallocation,Ada.Exceptions;
> procedure garbage is
>    ko : constant := 1024;
>    Mo : constant := ko*ko;
...
>    declare
>       type local_ptr is access tab_byte;
>       for local_ptr'storage_size use Mo*8;--[line 20]GNAT 3.15p raised
> STORAGE_ERROR : EXCEPTION_STACK_OVERFLOW

Read the fine manual.  In this case the gnat_rm will point you to
System.Pool_Size in s-poosiz.ads which says:

-----------------------------------------------------------------------------
    ------------------------
    -- Stack_Bounded_Pool --
    ------------------------

    --  Allocation strategy:

    --    Pool is a regular stack array, no use of malloc
    --    user specified size
    --    Space of pool is globally reclaimed by normal stack management

    --  Used in the compiler for access types with 'STORAGE_SIZE rep. clause
    --  Only used for allocating objects of the same type.

----------------------------------------------------------------------------

Translation, when you use 'Storage_Size in GNAT to set the storage for a 
type, the compiler takes that as a directive to allocate a 
local_ptr'storage_size array on the stack, in this case as part of the 
stack frame for the declare block.  If you comment the line out, the 
storage designated by local_ptr values will be allocated on the heap 
when new is called.

I suspect that you need to grow the stack size if you want to grab a 
megabyte in one chunk.

-- 
                                                     Robert I. Eachus

"Quality is the Buddha. Quality is scientific reality. Quality is the 
goal of Art. It remains to work these concepts into a practical, 
down-to-earth context, and for this there is nothing more practical or 
down-to-earth than what I have been talking about all along...the repair 
of an old motorcycle."  -- from Zen and the Art of Motorcycle 
Maintenance by Robert Pirsig




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

* Re: using 'storage_size ?
  2003-10-12 23:24 ` Robert I. Eachus
@ 2003-10-13 18:20   ` Alex Xela
  2003-10-13 18:53     ` Robert I. Eachus
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Xela @ 2003-10-13 18:20 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2299 bytes --]


-------------

Yes, but the gnat strategy should not matter with the fact that when I
define a pool of 8 Mo, I should be able to allocate at least 5Mo.
Alex.

-------------


"Robert I. Eachus" <rieachus@comcast.net> a �crit dans le message de news:
3F89E26E.40705@comcast.net...
> Alex Xela wrote:
> >
> > with ada.text_io,Unchecked_Deallocation,Ada.Exceptions;
> > procedure garbage is
> >    ko : constant := 1024;
> >    Mo : constant := ko*ko;
> ...
> >    declare
> >       type local_ptr is access tab_byte;
> >       for local_ptr'storage_size use Mo*8;--[line 20]GNAT 3.15p raised
> > STORAGE_ERROR : EXCEPTION_STACK_OVERFLOW
>
> Read the fine manual.  In this case the gnat_rm will point you to
> System.Pool_Size in s-poosiz.ads which says:
>
> --------------------------------------------------------------------------
---
>     ------------------------
>     -- Stack_Bounded_Pool --
>     ------------------------
>
>     --  Allocation strategy:
>
>     --    Pool is a regular stack array, no use of malloc
>     --    user specified size
>     --    Space of pool is globally reclaimed by normal stack management
>
>     --  Used in the compiler for access types with 'STORAGE_SIZE rep.
clause
>     --  Only used for allocating objects of the same type.
>
> --------------------------------------------------------------------------
--
>
> Translation, when you use 'Storage_Size in GNAT to set the storage for a
> type, the compiler takes that as a directive to allocate a
> local_ptr'storage_size array on the stack, in this case as part of the
> stack frame for the declare block.  If you comment the line out, the
> storage designated by local_ptr values will be allocated on the heap
> when new is called.
>
> I suspect that you need to grow the stack size if you want to grab a
> megabyte in one chunk.
>
> --
>                                                      Robert I. Eachus
>
> "Quality is the Buddha. Quality is scientific reality. Quality is the
> goal of Art. It remains to work these concepts into a practical,
> down-to-earth context, and for this there is nothing more practical or
> down-to-earth than what I have been talking about all along...the repair
> of an old motorcycle."  -- from Zen and the Art of Motorcycle
> Maintenance by Robert Pirsig
>





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

* Re: using 'storage_size ?
  2003-10-13 18:20   ` Alex Xela
@ 2003-10-13 18:53     ` Robert I. Eachus
  0 siblings, 0 replies; 7+ messages in thread
From: Robert I. Eachus @ 2003-10-13 18:53 UTC (permalink / raw)


Alex Xela wrote:
> -------------
> 
> Yes, but the gnat strategy should not matter with the fact that when I
> define a pool of 8 Mo, I should be able to allocate at least 5Mo.
> Alex.

It is the creation of the pool that is overflowing, not the allocation 
from the pool.  Incidently the reason that GNAT does it this way is that 
in many system designs getting Storage_Error "up front" is a much better 
  problem to have than getting a couple hours--or days into running your 
program, then run out of storage.  This is a common design practice in 
real-time systems.  All storage allocations are done during 
initialization, using sizes computed from the requirements documents.

-- 
                                                     Robert I. Eachus

"Quality is the Buddha. Quality is scientific reality. Quality is the 
goal of Art. It remains to work these concepts into a practical, 
down-to-earth context, and for this there is nothing more practical or 
down-to-earth than what I have been talking about all along...the repair 
of an old motorcycle."  -- from Zen and the Art of Motorcycle 
Maintenance by Robert Pirsig




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

end of thread, other threads:[~2003-10-13 18:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-12  7:37 using 'storage_size ? Alex Xela
2003-10-12 12:34 ` Duncan Sands
2003-10-12 14:12   ` Alex Xela
2003-10-12 18:23     ` Duncan Sands
2003-10-12 23:24 ` Robert I. Eachus
2003-10-13 18:20   ` Alex Xela
2003-10-13 18:53     ` Robert I. Eachus

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