comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: GNAT vs Matlab - operation on   multidimensional complex matrices
Date: Tue, 31 Mar 2020 13:05:58 -0700 (PDT)
Date: 2020-03-31T13:05:58-07:00	[thread overview]
Message-ID: <920be1a1-0b55-433b-8d9d-c9737198fb8f@googlegroups.com> (raw)
In-Reply-To: <6c2c0e35-af07-4169-8be5-464ec7fd0fd5@googlegroups.com>

IIRC, one method to ensure proper cleanup w/o using Unchecked Deallocation is to use Generics:

    Generic
        Type T is private;
        Type IndexA is (<>);
        Type IndexB is (<>);
        Type IndexC is (<>);
        Type Cubic is Array(IndexA, IndexB, indexC) of T;
        Default : in T;
    Package Test_Data is
        Type Access_Cubic is not null access all Cubic;
        
        Access_Data : Constant Access_Cubic := new Cubic'(others => (others => (others => Default)));
        Data        : Cubic renames Access_Data.all;
    End Test_Data;

Now you can do something like:

    COMPLEX_CUBE_TEST:
    Declare
        Package Test_Set is new Test_Data(
           T       => Complex,
           IndexA  => Channel,
           IndexB  => Angle,
           IndexC  => Range_T,
           Cubic   => tCubeComplex,
           Default => (Re => 1.0, Im => 1.0)
          );
        Complex_Cube : tCubeComplex renames Test_Set.Data;
        SComplex     : Complex;
    Begin
        TIO.Put_Line("Complex cube");
        TIO.Put_Line("Complex type size is:" & Integer'Image(Complex'Size));
        
        SpeedSumComplexCube(
           Mtx          => Complex_Cube,
           S            => SComplex,
           Iterations   => NumIteration
          );
        
        TIO.Put("Sum is:"); CTIO.Put(SComplex); TIO.New_Line;
    End COMPLEX_CUBE_TEST;

and upon exit of the COMPLEX_CUBE_TEST block your test-data is cleaned up when Test_Set is destroyed.

  parent reply	other threads:[~2020-03-31 20:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23 23:16 GNAT vs Matlab - operation on multidimensional complex matrices darek
2020-03-24  2:07 ` johnscpg
2020-03-24  6:40 ` J-P. Rosen
2020-03-24  9:37 ` Jeffrey R. Carter
2020-03-24 14:55   ` darek
2020-03-24 15:44 ` johnscpg
2020-03-31 17:25 ` Shark8
2020-03-31 19:20   ` Simon Wright
2020-03-31 19:54     ` Shark8
2020-04-29 21:08     ` vincent.diemunsch
2020-04-01 11:01   ` darek
2020-04-01 15:01     ` J-P. Rosen
2020-04-01 16:39       ` darek
2020-04-01 17:15         ` J-P. Rosen
2020-03-31 20:05 ` Shark8 [this message]
2020-03-31 20:51   ` Jeffrey R. Carter
2020-06-08 17:42 ` Shark8
replies disabled

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