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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,86ec22e070e319c0 X-Google-Attributes: gid103376,public From: robert_dewar@my-dejanews.com Subject: Re: How do I get this to work?? Date: 1999/01/16 Message-ID: <77q5m8$e4o$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 433307092 References: <76s0dp$1v4$1@nntp3.uunet.ca> <76tbvv$ba5$1@nntp3.uunet.ca> <770ifd$qui$1@goblin.uunet.ca> <771bl9$sla$1@nnrp1.dejanews.com> <77b9cp$5kh$1@nnrp1.dejanews.com> X-Http-Proxy: 1.0 x6.dejanews.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Sat Jan 16 13:54:18 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-01-16T00:00:00+00:00 List-Id: In article , warwicks@telusplanet.net (Chris Warwick) wrote: > Even from my Ada83 days, the only "safe" way to do > dynamic memory allocation was though the use of local > variables on the stack. If I understand this concept, > then the view is that it is better to point to a newly > allocated buffer, then it is to point to a procedure's > local variable. Exactly, and the reason is to avoid aliasing. This is a very familiar principle. Look at Pascal for example to see the start of this thread of design thinking, which Ada adopted. Ada 95 adds aliased variables, but they should be used with discretion! > Given that most Ada compilers have no way to deallocate > memory, That's simply wrong. Both Ada 83 and Ada 95 have a way to deallocate dynamic memory (Unchecked_Deallocation), and an Ada compiler not implementing this facility is impossible to imagine (and has never existed). > I seem to be trading the potential for a pointer to exist > past the life of the allocated memory for a program > continously allocates memory... Not clear what you are saying here. Certainly pointing to local variables on the stack has very dangerous possible consequences with regard to dangling pointers. The point here is that if you look at any program that uses the keyword ALIASED extensively, then this is almost always an example or importing C style into Ada (see separate thread on importing Pascal into COBOL :-) and is something that should be avoided. Almost always such code can be written to avoid the use of ALIASED, and the result will be improved, better structured code. Robert Dewar -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own