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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4a5bab72e3ac47fc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Dynamich Dispatching... Date: Mon, 04 Oct 2004 10:22:21 +0200 Organization: AdaCL Message-ID: <1265664.39nQz63IPR@linux1.krischik.com> References: <1511723.0R0PesaRS9@linux1.krischik.com> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1096879426 02 31282 yX4PX8FJeVkVSeG5 041004 08:43:46 X-Complaints-To: usenet-abuse@t-online.de X-ID: buwJM2ZQgexIrCxGaAw5PkXqatdOrfnkh4kBQuRgdfAWxP3UoCFVZI User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:4647 Date: 2004-10-04T10:22:21+02:00 List-Id: Brian May wrote: >>>>>> "Martin" == Martin Krischik writes: > > Martin> Avoid "access all" unless you need it. The compiler need > Martin> to do more checking when using "access all". > > Some references recommend using "all" - not sure why. "access all" can hold pointers to all sorts of elements. They may be on the stack or inside any user defined heap. Therfore they are far more flexible. However - all flexibility brings the change for error. For example I can think of at least 3 times as many things which can go wrong on an Unchecked_Deallocation for an "access all" then for an simple "access". Want to know? For access: Deallocating memory still in use. For access all: Deallocating memory still in use. Deallocating memory from the wrong storrage pool. Deallocating stack memory. See that's three times. > What extra > checking does it require? My references say when to use it, but never > say when not to use it My 2 cent: "access all" should not be used when user defined storrage pools are used as well. > or why it shouldn't be used if not required. access is allways allocated on one specific heap - So especially for library level access no live time check is needed. Ada prevents dangling pointer by making livetime checks. The classical C mistake int* f () { auto int Retval; return &Retval; } will cause an error in Ada - since Retval goes out of scope at function end. Most of the livetime checks are done at compile time - however there are a few to be done at run time. Important here is that for a named "access" - that is "type X is access Y" all livetime checks can be done at compile time. > >> procedure Main is > >> procedure Call_Dynamic(Object_Ptr: Objects.Object_Ptr) is > > Martin> procedure Call_Dynamic(Object: Objects.Object'Class) is > > >> begin > >> Objects.Draw(Object_Ptr.all); > > Martin> Objects.Draw(Object); > > >> end Call_Dynamic; > >> C2 : Circles.Circle; > > Martin> C3 : Object_Ptr := new Circles.Circle'Class'(C2); > > >> begin > >> C2 := Circles.Constructor.Create("Circle1",50); > >> Call_Dynamic (new Circles.Circle'(C2)); > > Martin> Call_Dynamic (C3); > > I think you meant "Call_Dynamic(C2)" here. You can't pass an access > type here... No I meant "Call_Dynamic(C3.all)". Of course you might not need a pointer at all. An Ada one can often use 'Class where in C++ a pointer or reference is needed. When I was 2 to 3 month into Ada I reorganised my Ada programs removing more then 80% of all pointers used until then. With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com