From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5b3aa4bc9027f04e X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!cyclone1.gnilink.net!spamkiller.gnilink.net!gnilink.net!nwrddc01.gnilink.net.POSTED!c9e1c1fe!not-for-mail From: Jeffrey Creem User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Unconstrained Arrays References: <1a8008fb-c840-45bc-824c-d10eec9fe569@d36g2000prf.googlegroups.com> <0caa9cf8-0620-4544-9b2c-2c9f24142b7f@v23g2000pro.googlegroups.com> In-Reply-To: <0caa9cf8-0620-4544-9b2c-2c9f24142b7f@v23g2000pro.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <40j396-m63.ln1@newserver.thecreems.com> Date: Tue, 17 Mar 2009 04:15:00 GMT NNTP-Posting-Host: 71.181.45.230 X-Complaints-To: abuse@verizon.net X-Trace: nwrddc01.gnilink.net 1237263300 71.181.45.230 (Tue, 17 Mar 2009 00:15:00 EDT) NNTP-Posting-Date: Tue, 17 Mar 2009 00:15:00 EDT Xref: g2news2.google.com comp.lang.ada:5124 Date: 2009-03-17T04:15:00+00:00 List-Id: belteshazzar wrote: > On Mar 17, 11:49 am, "Jeffrey R. Carter" > 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. > I think the problem here is you are assuming you need to pass a pointer to the function in order to avoid a copy. This is an incorrect assumption. Just make the function take in the unconstrained array. No large copy will be made.