comp.lang.ada
 help / color / mirror / Atom feed
From: belteshazzar <gbelteshazzar@gmail.com>
Subject: Re: Unconstrained Arrays
Date: Tue, 17 Mar 2009 16:00:53 -0700 (PDT)
Date: 2009-03-17T16:00:53-07:00	[thread overview]
Message-ID: <9f518ae2-3e67-447a-86ef-787c1437505a@40g2000yqe.googlegroups.com> (raw)
In-Reply-To: 73194169-cc24-428b-8f9e-c0740982bc79@i20g2000prf.googlegroups.com

On Mar 18, 1:33 am, Adam Beneschan <a...@irvine.com> wrote:
> On Mar 16, 7:58 pm, belteshazzar <gbelteshaz...@gmail.com> wrote:
>
>
>
>
>
> > On Mar 17, 11:49 am, "Jeffrey R. Carter"
>
> > <spam.jrcarter....@spam.acm.org> wrote:
> > > belteshazzar wrote:
> > > > I have a program that uses a lot of different sized arrays and passed
> > > > into math functions. So I'm using an unconstrained array type. The
> > > > problem that I have is that I'm not allowed to use "new" this means
> > > > that I have to use pools (which I can't because to intantiate a pool I
> > > > have to constrain the array type) or allocated the arrays on the
> > > > stack. Allocating the arrays on the stack is fine, BUT it means that i
> > > > have to use array initializers so that they remain unconstrained
> > > > rather than becoming an anonomous contrained type that can no longer
> > > > be passed to my math functions.
>
> > > I'm not clear what you're talking about. You can pass a constrained subtype to a
> > > subprogram that takes a parameter of an unconstrained array type.
>
> > > For example, String is an unconstrained array type. If we have
>
> > > function F (S : in String) return Natural;
>
> > > V : String (1 .. 10);
> > > C : Natural;
>
> > > then it's perfectly legal to call F with V as its actual parameter:
>
> > > C := F (S);
>
> > > > Also, and the main point of my post, I've found that I can place the
> > > > unconstrained array inside a record with a distriminant and this seems
> > > > to solve all our problems. We don't have to use array initialisers and
> > > > we can get pointers to aliased objects that can be easily passed to
> > > > the math functions.
>
> > > Here is your problem. There should be no reason to pass explicit pointers to
> > > these functions. Your best solution is to rewrite or change your library.
>
> > > --
> > > Jeff Carter
> > > "Drown in a vat of whiskey. Death, where is thy sting?"
> > > Never Give a Sucker an Even Break
> > > 106
>
> > As we have very large array's we're using something like:
>
> > type Unconstrained_Array is array ( Integer range <> ) of Integer;
> > type Unconstrained_Array_Pointer is access all Unconstrained_Array;
>
> > procedure F (S : in Unconstrained_Array_Pointer);
>
> > V : Unconstrained_Array := (1 .. 10_000 => 0);
> > V_Ptr : Unconstrained_Array_Ptr :=
> > Unconstrained_Array'unchecked_Access
>
> > F (V_Ptr);
>
> > Note the use of the array intialiaser, if this isn't used then the
> > pointer is no longer compatible.
>
> As Jeffrey C. and Jeffrey C. have pointed out, you shouldn't use
> pointers in your library routines.  Declare your library routines to
> have parameters of type Unconstrained_Array and don't worry about
> access types at all.  Ada makes things real simple if you let it.
>
> If for some reason you really need to use a pointer (like maybe your
> library is frozen and you can't change it without trying to sneak a
> library change requisition form past a vicious CM man-wolf), I think
> that in Ada 2005 you can improve performance with something like this:
>
> V : aliased Unconstrained_Array := (1 .. 10_000 => <>);
> V_Ptr : Unconstrained_Array_Ptr := V'Unchecked_Access;
>
> This uses the "default" initializer for the element type.  Since the
> default initializer for Integer is to leave it as undefined garbage,
> the compiler shouldn't generate any code to set up the array.  No
> guarantees, though; your compiler may do something anyway.
>
> Also, if you were able to use 'Unchecked_Access without making V
> aliased, your compiler is broken.
>
>                                 -- Adam- Hide quoted text -
>
> - Show quoted text -

Unfortuantely this is a 2005 feature and we're using 95 ... but thanks
for the tip.



  reply	other threads:[~2009-03-17 23:00 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-17  0:59 Unconstrained Arrays belteshazzar
2009-03-17  1:49 ` Jeffrey R. Carter
2009-03-17  2:58   ` belteshazzar
2009-03-17  4:15     ` Jeffrey Creem
2009-03-17  5:20     ` Jeffrey R. Carter
2009-03-17 17:56       ` Jeffrey R. Carter
2009-03-17 23:10         ` belteshazzar
2009-03-18 18:31           ` Jeffrey R. Carter
2009-03-20  1:53           ` Peter C. Chapin
2009-03-20  6:45             ` sjw
2009-03-20  9:46               ` Jacob Sparre Andersen
2009-03-20 11:40               ` Jean-Pierre Rosen
2009-03-25 21:11                 ` sjw
2009-03-25 22:30                   ` Robert A Duff
2009-03-25 23:28                     ` Randy Brukardt
2009-03-26  0:03                       ` Jeffrey R. Carter
2009-03-26  1:00                         ` Robert A Duff
2009-03-20 12:15               ` christoph.grein
2009-03-20 15:45               ` Adam Beneschan
2009-03-23  8:26                 ` belteshazzar
2009-03-25 21:21                 ` sjw
2009-03-25 22:03                   ` Adam Beneschan
2009-03-26  1:32                     ` tmoran
2009-03-27  8:39                   ` Jean-Pierre Rosen
2009-03-27 20:07                     ` sjw
2009-03-29 16:24                     ` sjw
2009-03-27 11:57                   ` Gautier
2009-03-17 15:33     ` Adam Beneschan
2009-03-17 23:00       ` belteshazzar [this message]
2009-03-17 20:14 ` anon
  -- strict thread matches above, loose matches on Subject: below --
2001-12-11 17:17 Unconstrained arrays Michael Unverzagt
2001-12-11 18:22 ` Stephen Leake
2001-12-11 18:24 ` Mark Lundquist
1993-08-15  5:01 Alex Blakemore
1993-08-13 21:08 J. Craig Heberle
1993-08-13 12:34 Paul Durbin
1993-08-12 21:23 Robert Dewar
1993-08-12 19:25 Wes Groleau x1240 C73-8
1993-08-12 17:27 agate!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.ed
1993-08-12 16:26 Mark A Biggar
1993-08-12 16:00 Dave Collar d x7468
1993-08-12 15:28 Robert I. Eachus
1993-08-12 15:00 Robert Dewar
1993-08-12 13:03 Raymond Blaak
1993-08-12 12:14 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.
1993-08-12 12:03 cis.ohio-state.edu!pacific.mps.ohio-state.edu!math.ohio-state.edu!magnus.
1993-08-11 23:42 Kenneth Anderson
1993-08-11 23:40 cis.ohio-state.edu!math.ohio-state.edu!cs.utexas.edu!swrinde!menudo.uh.ed
1993-08-11 22:29 Kenneth Anderson
replies disabled

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