From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Leo Brewin Newsgroups: comp.lang.ada Subject: Re: Real_Arrays on heap with overloaded operators and clean syntax Date: Mon, 23 Jan 2023 12:14:47 +1100 Organization: A noiseless patient Spider Message-ID: References: <9c7cccd9-733f-49a8-b482-087ccb14b58dn@googlegroups.com> <3db6b678-5a45-4b4d-9f6c-e4933b04d6c2n@googlegroups.com> <6dbff95d-8e30-4a60-ad03-d0aa4cff1583n@googlegroups.com> <49c1bfc5-38aa-4360-81f3-c95f867160een@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 23 Jan 2023 01:14:56 -0000 (UTC) Injection-Info: reader01.eternal-september.org; posting-host="68997e19f82c6234f32f8c0c0d45392a"; logging-data="3512992"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9Jz5SEJzx9EpK1pRkFFLW8H2ihEeGtc6LiHGwU4DHyw==" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Cancel-Lock: sha1:PIllB/S+Qir16Fr9XGnFVOfwuvA= In-Reply-To: <49c1bfc5-38aa-4360-81f3-c95f867160een@googlegroups.com> Xref: reader01.eternal-september.org comp.lang.ada:64862 List-Id: Here is a slight variation on the solution suggested by Gautier. It uses Aad's "rename" syntax so that you can avoid all the .all stuff. I use this construction extensively in my large scale scientific computations. with Ada.Numerics.Generic_Real_Arrays; with Ada.Unchecked_Deallocation; procedure Test_Large is type Float_15 is digits 15; package F15_R_A is new Ada.Numerics.Generic_Real_Arrays (Float_15); use F15_R_A; procedure Solve_it (x : in Real_Vector; y : out Real_Vector; A : in Real_Matrix) is begin null; -- Here, the big number-crunching end; n : constant := 10_000; type Vector_Access is access Real_Vector; type Matrix_Access is access Real_Matrix; x_ptr, y_ptr : Vector_Access := new Real_Vector (1 .. n); A_ptr : Matrix_Access := new Real_Matrix (1 .. n, 1 .. n); x : Real_Vector renames x_ptr.all; y : Real_Vector renames y_ptr.all; A : Real_Matrix renames A_ptr.all; procedure FreeVector is new Ada.Unchecked_Deallocation (Real_Vector,Vector_Access); procedure FreeMatrix is new Ada.Unchecked_Deallocation (Real_Matrix,Matrix_Access); begin Solve_it (x, y, A); -- Deallocation here FreeVector (x_ptr); FreeVector (y_ptr); FreeMatrix (A_ptr); end;