comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon.j.wright@mac.com>
Subject: Re: Pointers explained?
Date: Tue, 31 Jul 2007 18:21:30 +0100
Date: 2007-07-31T18:21:30+01:00	[thread overview]
Message-ID: <m2vec0h4kl.fsf@mac.com> (raw)
In-Reply-To: 1185818189.689914.159900@x40g2000prg.googlegroups.com

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.



  parent reply	other threads:[~2007-07-31 17:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-30 17:53 Pointers explained? shaunpatterson
2007-07-30 17:56 ` shaunpatterson
2007-07-30 19:04   ` Ed Falis
2007-07-30 19:05   ` Ludovic Brenta
2007-07-30 19:36   ` Adam Beneschan
2007-07-30 21:23     ` Maciej Sobczak
2007-07-30 22:36       ` Adam Beneschan
2007-07-31  7:33         ` Dmitry A. Kazakov
2007-07-31  1:15       ` Anh Vo
2007-07-30 22:20     ` Adam Beneschan
2007-07-30 21:31   ` Jeffrey R. Carter
2007-07-31 17:21   ` Simon Wright [this message]
2007-07-31 18:06     ` Dmitry A. Kazakov
2007-07-31 22:38       ` shaunpatterson
2007-08-01  7:53         ` Martin Krischik
2007-08-01  8:21         ` Dmitry A. Kazakov
2007-08-10 19:52         ` Simon Wright
2007-07-30 20:11 ` Dmitry A. Kazakov
2007-07-31  8:28 ` Martin Krischik
  -- strict thread matches above, loose matches on Subject: below --
2007-07-30 17:53 shaunpatterson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox