comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: using 'storage_size ?
Date: Sun, 12 Oct 2003 23:24:06 GMT
Date: 2003-10-12T23:24:06+00:00	[thread overview]
Message-ID: <3F89E26E.40705@comcast.net> (raw)
In-Reply-To: 3f8904a1$0$10406$626a54ce@news.free.fr

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




  parent reply	other threads:[~2003-10-12 23:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2003-10-13 18:20   ` Alex Xela
2003-10-13 18:53     ` Robert I. Eachus
replies disabled

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