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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cd962bca2451dfbc X-Google-Attributes: gid103376,public From: Mark Elson Subject: Re: static objects in ADA Date: 1999/04/25 Message-ID: <4IaN6CA84vI3EwTh@tioman.demon.co.uk>#1/1 X-Deja-AN: 470648695 X-NNTP-Posting-Host: tioman.demon.co.uk:158.152.120.33 References: <7foacg$3t1@news1.newsguy.com> X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 925040404 nnrp-03:10905 NO-IDENT tioman.demon.co.uk:158.152.120.33 Organization: SSL MIME-Version: 1.0 Reply-To: Mark Elson Newsgroups: comp.lang.ada Date: 1999-04-25T00:00:00+00:00 List-Id: First of all thanks to all who replied to this thread, they have all been very useful especially Sam's >Mark Elson asked: >> Is there an equivalent declaration (in ADA 95) to the static used in >> C++, i.e. so that objects are created at link time rather than at run >> time? > >Depends on what you mean. > >Vocabulary: I'll use "C-static" to refer to the "static" variables of >C and C++. "Static" is used differently in the Ada manual. > >As others have told you, Ada variables declared in a library package >spec or body (not contained in a procedure or function declaration) >are C-static. > I slipped up here in my terminology - whilst I was thinking of static initialisation being at compile/link time the relevant C++ keyword is actually const. What prompted me to think of this approach is the common use of const character arrays to store config control info as strings in object files. >> I am being told that using objects will >> greatly increase my app start time because of object creation overhead. >> Any comments appreciated. > >Hmm. I wonder if this advice is oriented toward C++. > >Vocabulary: I'll reserve "object" for object-oriented entities, that >is, an instance of a class in C++ or a value of a tagged type in Ada. >I'll assume that's what you're talking about here. I'll use "item" >to mean a regular variable. The Ada Reference Manual refers to >anything that uses memory (variables, constants, tasks, protected >objects) as an "object." > >Perhaps your advice refers to dynamic memory allocation. I believe >that some object-oriented features in C++ depend on an "object" being >referred to by a pointer, but I didn't think they had to be allocated >at run-time. That is, I thought you could take the address of an >"automatic" variable and use that. You're quite right - virtual functions can be called through pointers or references to automatic variables (so long as they still exist, of course). The "advice" has really annoyed me. It came from Green Hills and they were actually telling us that we should abandon an object-orientated design and use structured methods instead to avoid the overhead of object initialisation (which they believed would give us "long" start-up times). In fact, we are not creating any significantly large objects at start-up time, anyway, so I felt this was very bad advice. IMO, at the implementation level OO and structured methods might only differ in the organisation of code. There should be no reason why OO-designed code should be inherently less efficient than a structured design. Possibly inefficient activities such as dynamic memory allocation can be avoided, by design, if required. In fact we intend to do this for other reasons as the app will be safety-critical. Thanks again for the replies. -- Mark Elson