comp.lang.ada
 help / color / mirror / Atom feed
From: NiGHTS <nights@unku.us>
Subject: Re: Variant record memory storage question
Date: Wed, 1 Aug 2018 11:51:48 -0700 (PDT)
Date: 2018-08-01T11:51:48-07:00	[thread overview]
Message-ID: <b34524f8-5d55-44ed-a6d6-fcab2ea9b96f@googlegroups.com> (raw)
In-Reply-To: <2289a8c3-043f-4270-9c16-78a91f0bb2bf@googlegroups.com>

On Wednesday, August 1, 2018 at 2:35:38 PM UTC-4, Shark8 wrote:
> On Wednesday, August 1, 2018 at 11:38:06 AM UTC-6, NiGHTS wrote:
> > Say I had a variant record like this:
> > 
> > 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;
> > 
> > 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?
> > 
> > I am trying to determine the most memory-efficient way to store a complex record and it seems Variant_Record can help me do this, but I am unsure if it will work the way I think it will.
> > 
> > Note I am using gcc. Thank you.
> 
> The standard allows for it to be stored as 1-byte, as you desire, but does not require this behavior. Since you are using GCC, I can tell you that it uses the second behavior: because GCC / GNAT views compatibility with C as a very high priority, and also because it's easier to do it that way.
> 
> Dmitry, Randy, and/or Simon can probably give you more. (And might have a solution for you.)

Could I use a pragma to give the compiler an explicit request to store the data in the smallest possible way? I would think the option should exist to hint to the compiler that I don't care about C compatibility for this record.


  reply	other threads:[~2018-08-01 18:51 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 [this message]
2018-08-01 19:00     ` G.B.
2018-08-01 18:58 ` G.B.
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