From: Stephen Leake <stephen_leake@acm.org>
To: comp.lang.ada@ada-france.org
Subject: Re: renames and access
Date: 11 Feb 2004 21:32:02 -0500
Date: 2004-02-11T21:32:02-05:00 [thread overview]
Message-ID: <mailman.16.1076553136.295.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <pan.2004.02.11.19.14.49.293492@virgilio.it>
"Francesco Bochicchio" <bockman@virgilio.it> writes:
> Hi all,
>
> I have a piece of code that does something like this:
>
> type REC_T is record
> A : Integer;
> B : String(4)
> end record;
>
> type REC_PTR_T is access REC_T;
> REC_PTR : REC_PTR_T := new REC_T;
>
> A renames REC_PTR.A;
> B renames REC_PTR.B;
>
> At this point, I can use A and B as if they where simple
> variables. BUT, when I later reallocate the memory like this:
>
> function REALLOCATE_MEMORY return REC_PTR_T;
> REC_PTR := REALLOCATE_MEMORY(); -- Actually, the ability to reallocate is
> -- the reason for all this fuss.
> --
>
> then A and B still points to the old memory, not at the one currently
> pointed by REC_PTR.
>
> Is this normal ??
Yes. The result of the rename statements is cached.
> Is there any way
> to have the renames to automatically points to the new memory?
You have to evaluate them again after you change Rec_Ptr:
loop
rec_ptr := Reallocate_Memory;
declare
a : Integer renames REc_ptr.a;
b : string (4) renames REc_Ptr.b;
begin
...
end;
end loop
> If this turns impossible, what would be an equivalent solution?
I need to see more context to suggest other ways of proceeding. Do you
have a loop like I wrote above?
> BACKGROUND : the reason for all this is that we are trying to add a
> failover capability to a very old application of many thousand lines
> of code. Therefore, the 'critical variables' (one hundred or more) shall
> be allocated in a special area of memory which is mirrored between the
> primary machine and its backup, where a copy of the application
> runs in hot standby. The trick with the renames should have spared us from
> changing every line of code referring to one of these variables.
Change the variables into equivalently named functions, whose bodies
reference the pointer.
--
-- Stephe
next prev parent reply other threads:[~2004-02-12 2:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-11 19:15 renames and access Francesco Bochicchio
2004-02-11 22:09 ` Randy Brukardt
2004-02-12 0:02 ` Robert A Duff
2004-02-12 18:36 ` Francesco Bochicchio
2004-02-13 8:30 ` Martin Dowie
2004-02-13 20:33 ` Robert I. Eachus
2004-02-12 2:32 ` Stephen Leake [this message]
2004-02-12 18:30 ` Francesco Bochicchio
2004-02-13 19:01 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox