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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e7536778f913e61a X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed101.telia.com!nf02.dk.telia.net!news.tele.dk!news.tele.dk!small.news.tele.dk!bnewspeer01.bru.ops.eu.uu.net!emea.uu.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 24 Apr 2009 17:48:56 +0200 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.21 (Macintosh/20090302) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Exception handling overhead? References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Message-ID: <49f1df69$0$31330$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 24 Apr 2009 17:48:57 CEST NNTP-Posting-Host: 5043f7ed.newsspool4.arcor-online.net X-Trace: DXC=808]dCcDgYOlU`@c^jLCbJ4IUKMO;9OJDO8_SKFNSZ1n^B98iJ?C`P2YC07VJ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:4567 Date: 2009-04-24T17:48:57+02:00 List-Id: anon schrieb: > You must disable the compiler default Range checking, like: Or Index_Check. However, this only gives an implementation permission to omit certain checks. So I wonder whether pragma Suppress ( *_Check ) will have an effect on the library code, or whether the library will have to be recompiled, and then, whether recompilation of the library will still produce correct code. > > function Element( B : Buffer; Index : Positive ) return Character is > > begin > declare > -- Temporary disable system checks > > pragma Suppress ( Range_Check ) ; > begin > if Index > Ada.Strings.Unbounded.Length ( B.Internal_String ) then > raise Bad_Index ; > end if ; > end ; > return Ada.Strings.Unbounded.Element ( B.Internal_String, Index ) ; > end Element ; > > > In , "Peter C. Chapin" writes: >> Hello! >> >> I'm creating a type intended to represent lines of editable text. It >> will provide some specialized services and is not intended to be a >> general purpose string type. At the moment I'm wrapping the type >> Ada.Strings.Unbounded.Unbounded_String (I'm really using Wide_Strings, >> but I don't think that's important right now). I may want to change that >> underlying implementation in the future so I don't want to directly >> expose my current choice to my clients. Thus I'm providing some >> subprograms that do some minor things and then just forward to >> subprograms in Ada.Strings.Unbounded. >> >> My question is about exceptions. To avoid exposing my implementation >> choice and to give me more control in the long run I've defined my own >> exception for (as an example) an out of bounds access: >> >> Bad_Index : exception; >> >> Naturally I want to raise this exception if the client tries to access a >> character not in my buffer. This leads to two possibilities. >> >> function Element(B : Buffer; Index : Positive) return Character is >> begin >> if Index > Ada.Strings.Unbounded.Length(B.Internal_String) then >> raise Bad_Index; >> end if; >> return Ada.Strings.Unbounded.Element(B.Internal_String, Index); >> end Element; >> >> This entails two checks on the index value: the one I'm doing and the >> one being done inside Ada.Strings.Unbounded.Element. Another approach is >> >> function Element(B : Buffer; Index : Positive) return Character is >> begin >> return Ada.Strings.Unbounded.Element(B.Internal_String, Index); >> exception >> when Ada.Strings.Index_Error => >> raise Bad_Index; >> end Element; >> >> This lets the check exist in only one place but it invokes the machinery >> of exception handling. >> >> Now I know that in C++ there are implementation methods that allow zero >> execution time overhead in the case when an exception is not thrown (at >> the expense of increasing executable size and making thrown exceptions >> slower). Compilers are not required to use such methods, of course, but >> I know of at least one that does... or that can if the right options are >> selected. I'm wondering about how this might work in Ada. Does Ada admit >> such implementation methods? If so, do compilers commonly use them? From >> a raw performance point of view which of the two approaches above would >> be "better?" >> >> For the record... I understand that in my application it probably >> doesn't matter much either way. I also understand that the answer is >> likely to be very compiler specific. This is mostly a question of >> academic interest. >> >> Thanks! >> >> Peter > -- -- Georg Bauhaus Y A Time Drain http://www.9toX.de