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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,308a261188818cce X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.glorb.com!peer1.news.newnet.co.uk!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!mutlu.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Pointers explained? Date: Tue, 31 Jul 2007 18:21:30 +0100 Organization: Pushface Message-ID: References: <1185817996.143086.317990@g12g2000prg.googlegroups.com> <1185818189.689914.159900@x40g2000prg.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1185902491 6937 62.49.19.209 (31 Jul 2007 17:21:31 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Tue, 31 Jul 2007 17:21:31 +0000 (UTC) Cancel-Lock: sha1:BTDKiwe6NclyCV7y0n5vev+0R30= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin) Xref: g2news2.google.com comp.lang.ada:1294 Date: 2007-07-31T18:21:30+01:00 List-Id: shaunpatterson@gmail.com writes: > type Message is abstract tagged null record; > type Message_Class is access all Message'Class; > > > then all other messages are derived from this. > > > Now from my factory create method, I'm returning a Message_Class. > This message_class is stored in another record to be handled again > later: > > > type CallbackEvent is > record > msg : Message_Class; > ... > end record; Could you have an abstract operation dispatching on Message? procedure Handler (M : Message); (of course you could add extra parameters as required to correspond to your ... in CallbackEvent). > Now my basic problem -- or not really a problem -- is that to create > the Message_Class I have to use "new" and allocate and deallocate > memory. Not clear why this is a problem? On the 1.5 GHz Powerbook it takes about 1 us to allocate, 1.5 us to deallocate 32 bytes. If you are worried about losing track of allocations and running out of storage, you could consider some sort of smart pointer scheme (the Booch Components at http://booch95.sf.net have such a thing, or you could roll your own). Or you could adopt a "procedural" approach -- individual posters of events do the 'new', but the event queue manager does the deallocation. I don't believe you can have a queue of messages like this without 'new'. If you just want to handle the messages in the context where they're created, you may be able to swing it.