From: "G.B." <bauhaus@notmyhomepage.invalid>
Subject: Re: Variant record memory storage question
Date: Wed, 1 Aug 2018 20:58:46 +0200
Date: 2018-08-01T20:58:46+02:00 [thread overview]
Message-ID: <pjsvt7$9o2$1@dont-email.me> (raw)
In-Reply-To: <6cfb0a23-91d0-4ebe-9291-426280e12913@googlegroups.com>
On 01.08.18 19:38, NiGHTS wrote:
> Will the record Variant_Record( Is_Small ) be stored as 1 byte? Or does it act almost like a C union allocating the memory for Variant_Record( Is_Big ) even though it will never morph at run-time?
(You could also try pragma Unchecked_Union.)
GCC's -gnatRn has hints that will help answer the question.
Using defaults for representation,
package Rep is
type Byte is mod 512;
type Some_Large_Array is array (1 .. 1_000) of Byte;
type Some_Large_Record is
record
Data : Some_Large_Array;
end record;
type Which_One is (Is_Small, Is_Big);
type Variant_Record (Option : Which_One) is
record
case Option is
when Is_Small =>
Var_1 : Byte; -- 1 byte
when Is_Big =>
Var_2 : Some_Large_Record; -- 1000 bytes
end case;
end record;
S : Variant_Record (Is_Small);
B : Variant_Record (Is_Big);
end Rep;
$ gcc -c -x ada -gnatR2 rep.ads
Representation information for unit Rep (spec)
----------------------------------------------
for Byte'Object_Size use 16;
for Byte'Value_Size use 9;
for Byte'Alignment use 2;
for Some_Large_Array'Size use 16000;
for Some_Large_Array'Alignment use 2;
for Some_Large_Array'Component_Size use 16;
for Some_Large_Record'Size use 16000;
for Some_Large_Record'Alignment use 2;
for Some_Large_Record use record
Data at 0 range 0 .. 15999;
end record;
for Which_One'Object_Size use 8;
for Which_One'Value_Size use 1;
for Which_One'Alignment use 1;
for Variant_Record'Object_Size use 16016;
for Variant_Record'Value_Size use ??;
for Variant_Record'Alignment use 2;
for Variant_Record use record
Option at 0 range 0 .. 7;
Var_1 at 2 range 0 .. 15;
Var_2 at 2 range 0 .. 15999;
end record;
for S'Size use 32;
for S'Alignment use 4;
for B'Size use 16016;
for B'Alignment use 2;
--
"HOTDOGS ARE NOT BOOKMARKS"
Springfield Elementary teaching staff
next prev parent reply other threads:[~2018-08-01 18:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-01 17:38 Variant record memory storage question NiGHTS
2018-08-01 18:35 ` Shark8
2018-08-01 18:51 ` NiGHTS
2018-08-01 19:00 ` G.B.
2018-08-01 18:58 ` G.B. [this message]
2018-08-01 19:54 ` Niklas Holsti
2018-08-01 22:30 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox