comp.lang.ada
 help / color / mirror / Atom feed
From: Leo Brewin <Leo.Brewin@monash.edu>
Subject: Re: Real_Arrays on heap with overloaded operators and clean syntax
Date: Mon, 23 Jan 2023 12:14:47 +1100	[thread overview]
Message-ID: <tqkn2f$3b6l0$1@dont-email.me> (raw)
In-Reply-To: <49c1bfc5-38aa-4360-81f3-c95f867160een@googlegroups.com>

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;

  reply	other threads:[~2023-01-23  1:14 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-22 21:34 Real_Arrays on heap with overloaded operators and clean syntax Jim Paloander
2023-01-22 21:56 ` Joakim Strandberg
2023-01-22 22:07   ` Jim Paloander
2023-01-22 22:42     ` Joakim Strandberg
2023-01-22 22:49       ` Jim Paloander
2023-01-22 23:11         ` Joakim Strandberg
2023-01-22 23:14         ` Gautier write-only address
2023-01-23  1:14           ` Leo Brewin [this message]
2023-01-23  6:01             ` Jim Paloander
2023-01-23  8:39     ` G.B.
2023-01-22 22:13 ` Dmitry A. Kazakov
2023-01-22 22:36   ` Jim Paloander
2023-01-23  8:28     ` Dmitry A. Kazakov
2023-01-24  1:04       ` Jim Paloander
2023-01-24 10:42         ` J-P. Rosen
2023-01-25  9:52           ` Jim Paloander
2023-01-25 12:21             ` J-P. Rosen
2023-01-25 22:41               ` Gautier write-only address
2023-01-26 19:08                 ` Jim Paloander
2023-01-22 23:18 ` Rod Kay
2023-01-22 23:20   ` Jim Paloander
2023-01-22 23:34     ` Rod Kay
2023-01-22 23:53       ` Joakim Strandberg
2023-01-23  7:50         ` Egil H H
2023-01-23  8:51           ` J-P. Rosen
2023-01-23  6:34       ` Rod Kay
2023-01-23  6:56         ` Jim Paloander
2023-01-23  7:31           ` Rod Kay
2023-01-24 19:47 ` Gautier write-only address
2023-01-24 23:02   ` Gautier write-only address
2023-01-25  9:50     ` Jim Paloander
2023-01-26 20:39 ` Jerry
2023-01-26 21:52   ` Jim Paloander
2023-02-02 21:59     ` Jerry
replies disabled

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