comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: unconstrained records
Date: Fri, 27 Dec 2002 14:34:27 -0600
Date: 2002-12-27T14:34:27-06:00	[thread overview]
Message-ID: <v0pe9itgmc0d7f@corp.supernews.com> (raw)
In-Reply-To: wccn0mxeui6.fsf@shell01.TheWorld.com

Robert A Duff wrote in message ...
>see@messagebody.com (Jan) writes:
>
>> So when I write the following code (this one works), the string in
>> "name" will ALWAYS occupy 15 bytes?
>>
>>    subtype Max_Index is Natural range 0 .. 15;
>>
>>    type Test (length : natural := 0) is
>>      record
>>         text : string (1..length);
>>      end record;
>>
>> name : Test;
>
>On most Ada compilers, that's true.  There are (or were) *some* Ada
>compilers that used implicit heap allocation to implement this sort of
>thing, so that when you assign a different-sized value, the old one
gets
>deallocated and the new one allocated.

Janus/Ada has always done this. I've always found the "standard"
implementation suspicious, because it isn't what the programmer wrote.
OTOH, it is better for embedded systems (because it is more
deterministic), so that's why most of them use it.

>It's quite difficult to get the heap-based implementation right.
Consider renaming
>Name.Text(3), for example.

You're right that it is difficult, but renaming isn't a problem: it's
illegal by 8.5.1(5). The primary problem is getting rid of the
heap-allocated stuff when the object goes out of scope. For nested
scopes, you don't want it to hang around. That problem was complicated
by storage pools (you really want to use the correct pool for the
allocation, but then you have to use the correct pool for deallocation,
meaning you have to save it somewhere).

            Randy Brukardt.








  reply	other threads:[~2002-12-27 20:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-22 12:24 unconstrained records Jan
2002-12-22 13:52 ` SteveD
2002-12-22 18:54   ` Jan
2002-12-22 19:14     ` Robert A Duff
2002-12-27 20:34       ` Randy Brukardt [this message]
2002-12-23  4:30     ` SteveD
replies disabled

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