The following code present a Finalize procedure with a parameter of
access tagged class type in order to deallocate the memory of the given parameter from the root tagged type TTA and his children.
The same for TTB which is inherited from TTA. But this Finalize call
Finalize of TTA.
It may be not the best idea.
But let's see:
with Ada.Unchecked_Deallocation;
procedure test_20231113_free_tag is
type TTA is tagged record
AA : Integer;
end record;
type ATTA is access all TTA;
type CATTA is access all TTA'Class;
procedure Finalize (O : in out CATTA) is
procedure Free is new Ada.Unchecked_Deallocation (TTA, ATTA);
begin
Free (ATTA (O));
end Finalize;
type TTB is new TTA with record
BB : Integer;
end record;
type ATTB is access all TTB;
type CATTB is access all TTB'Class;
procedure Finalize (O : in out CATTB) is
begin
Finalize (CATTA (O));
end Finalize;
OA : CATTA := new TTA;
OB : CATTB := new TTB;
begin
Finalize (OA);
Finalize (OB);
end test_20231113_free_tag;
The procedure Free is the instanciation of Unchecked_Deallocation with
the tagged type TTA.
Thus the call "Finalize (OA);" deallocate the memory of object OA of
type access class TTA.
But what does "Finalize (OB);"?
But what does "Finalize (OB);"?
Crashes your program. It is a bug. You should instantiate Unchecked_Deallocation with class-wide type if you pass a class-wide
pointer.
Le 14/11/2023 à 23:42, Dmitry A. Kazakov a écrit :
But what does "Finalize (OB);"?
Crashes your program. It is a bug. You should instantiate
Unchecked_Deallocation with class-wide type if you pass a class-wide
pointer.
Thanks, I haven't considered this possibility.
Note: the previous program built with GNAT FSF 13.2.0 ran without
exception.
I've changed:
with Ada.Unchecked_Deallocation;
procedure test_20231113_free_class is
type TTA is tagged record
AA : Integer;
end record;
type ATTA is access all TTA;
type CATTA is access all TTA'Class;
procedure Finalize (O : in out CATTA) is
procedure Free is new Ada.Unchecked_Deallocation (TTA'Class, CATTA);
begin
Free (O);
end Finalize;
type TTB is new TTA with record
BB : Integer;
end record;
type ATTB is access all TTB;
type CATTB is access all TTB'Class;
procedure Finalize (O : in out CATTB) is
begin
Finalize (CATTA (O));
end Finalize;
OA : CATTA := new TTA;
OB : CATTB := new TTB;
begin
Finalize (OA);
Finalize (OB);
end test_20231113_free_class;
It runs without exception.
One question remains about "Finalize (OB);":
Which memory size is deallocated TTA'Size or TTB'Size?
On 2023-11-15 21:26, Blady wrote:<...>
Le 14/11/2023 à 23:42, Dmitry A. Kazakov a écrit :
But what does "Finalize (OB);"?
Regarding Unchecked_Deallocation instantiated with a pointer to a
class-wide object, consider it dispatching on the target object tag.
Thus you can deallocate any object using any instance of Unchecked_Deallocation for any class-wide parent of, interfaces included.
So Finalize (OB) is OK.
Thanks, yes, the instanciation of Unchecked_Deallocation seemed to
indicate that but I was not able to confirm it from the Ada RM.
A mention in Ada RM 13.11.2 Unchecked Storage Deallocation of that
particular possibility would be valuable.
Blady schrieb am Donnerstag, 16. November 2023 um 21:29:20 UTC+1:nonsense - I mean class types
Thanks, yes, the instanciation of Unchecked_Deallocation seemed totype Object(<>) is limited private;
indicate that but I was not able to confirm it from the Ada RM.
A mention in Ada RM 13.11.2 Unchecked Storage Deallocation of that particular possibility would be valuable.
The box here denotes unknown discriminants, i.e. indefinite types - these include task types;
limited is "assume the worst" => i.e. any type may be used as actual type for this formal type.
SUMBAWATOTO>> SLOT Garansi MENANG
⚡️⚡️MEMBER BARU DAFTAR DISINI DIJAMIN JP⚡️⚡️SUMBAWATOTO SUMBAWASLOT SUMBAWAGACOR: LINK LOGIN MASUK SITUS SUMBAWASLOTGACOR kliks.gif
Link Daftar SUMBAWATOTO 👉🏻👉🏻
✅ Minimal Deposit : Rp 10.000-
✅ Minimal Withdraw : Rp. 50.000-
✅ Metode Deposit : Bank , E-money, Dan Qris
⏰ Proses Deposit 1 Menit
⏰ Proses Withdraw 3 Menit
❌ Tidak Banyak Drama
DAFTAR <<<<<
LOGIN <<<<<
SUMBAWATOTO>> SLOT Garansi MENANG
█▀ █░░ █▀█ ▀█▀ █▀▀ ▄▀█ █▀▀ █▀█ █▀█It seems like it is gprbuid that is issing. Where can I find it?
▄█ █▄▄ █▄█ ░█░ █▄█ █▀█ █▄▄ █▄█ █▀▄
▁ ▂ ▄ ▅ ▆ ▇ █ 𝐋𝐈𝐍𝐊 𝐃𝐀𝐅𝐓𝐀𝐑 █ ▇ ▆ ▅ ▄ ▂ ▁
⚡️⚡️MEMBER BARU DAFTAR DISINI DIJAMIN JP⚡️⚡️
Link Daftar SUMBAWATOTO 👉🏻👉🏻
✅ Minimal Deposit : Rp 10.000-
✅ Minimal Withdraw : Rp. 50.000-
✅ Metode Deposit : Bank , E-money, Dan Qris
⏰ Proses Deposit 1 MenitSUMBAWATOTO SUMBAWASLOT SUMBAWAGACOR: LINK LOGIN MASUK SITUS SUMBAWASLOTGACOR
⏰ Proses Withdraw 3 Menit
❌ Tidak Banyak Drama
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWASLOT ✅ https://sumbawatotoslot.link.kr/togelsumbapro SUMBAWATOGEL ✅ https://www.iglinks.io/sumbawaslot-8fb?preview=true
SUMBAWATOTO>> SLOT Garansi MENANG
⚡️⚡️MEMBER BARU DAFTAR DISINI DIJAMIN JP⚡️⚡️SUMBAWATOTO SUMBAWASLOT SUMBAWAGACOR: LINK LOGIN MASUK SITUS SUMBAWASLOTGACOR
Link Daftar SUMBAWATOTO 👉🏻👉🏻
✅ Minimal Deposit : Rp 10.000-
✅ Minimal Withdraw : Rp. 50.000-
✅ Metode Deposit : Bank , E-money, Dan Qris
⏰ Proses Deposit 1 Menit
⏰ Proses Withdraw 3 Menit
❌ Tidak Banyak Drama
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (2 / 14) |
Uptime: | 65:10:41 |
Calls: | 8,355 |
Calls today: | 15 |
Files: | 13,159 |
Messages: | 5,893,953 |
Posted today: | 1 |