From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8c350c9f790688d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-02-11 18:33:21 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!nnx.oleane.net!oleane!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: renames and access Date: 11 Feb 2004 21:32:02 -0500 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1076553136 58485 80.67.180.195 (12 Feb 2004 02:32:16 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Thu, 12 Feb 2004 02:32:16 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.3 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:5468 Date: 2004-02-11T21:32:02-05:00 "Francesco Bochicchio" 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