• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How To Design A Queue of Messages?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How To Design A Queue of Messages?


  • Subject: Re: How To Design A Queue of Messages?
  • From: John Stiles <email@hidden>
  • Date: Sat, 10 Sep 2005 09:29:58 -0700



Mietek Bąk wrote:

On 10/9/2005, at 17:08, Tommy Nordgren wrote:

The easiest way to do this is probably to code this module in Objective C++,
and use std::queue tmmplates, instantiated with a suitable enum.


I respectfully disagree. A queue is one of the simplest data structures, trivial to implement, and the problem Jerry is having isn't related to the nature of the queue. The STL is overkill for such an application, and Andreas already suggested a method much more elegant and dynamic than a switch statement.

A std::queue is overkill? A queue is /exactly what std::queue is designed to do/. It's pretty much ideally suited to the task.
Then again, NSMutableArray has basically the same kind of stuff. You can add onto the back and remove from the front, etc. I think it would basically be the same either way, in terms of efficiency and in terms of lines-of-code.
If I were implementing it, I think it'd be something like this (using std::queue just to show that you can):


@interface MyQueueableObject1 (QueueAdditions)
// It is your job to implement "executedQueuedTask" so that it does whatever you
// want it to do with this object.
-executeQueuedTask;
@end
@interface MyQueueableObject2 (QueueAdditions)
-executeQueuedTask;
@end



// these go wherever they need to go--static? inside an object? etc.
// whether you actually need retain/release is up to you and your code structure
queue<id> tasks;



void DispatchOneTask() { if( !tasks.empty() ) { id obj = tasks.front(); tasks.pop_front(); [obj executeQueuedTask]; [obj release]; } }


void QueueOneTask( id obj ) { tasks.push_back( [obj retain] ); }


Anyway, this is dead simple stuff. Not worth arguing over.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How To Design A Queue of Messages? (From: Jerry Krinock <email@hidden>)
 >Re: How To Design A Queue of Messages? (From: Tommy Nordgren <email@hidden>)
 >Re: How To Design A Queue of Messages? (From: Mietek Bąk <email@hidden>)

  • Prev by Date: clickable text fields?
  • Next by Date: Re: NSView to NSBitmapRep Without an NSWindow?
  • Previous by thread: Re: How To Design A Queue of Messages?
  • Next by thread: NSArrayController and tables: the "All" item and indirect relationship sets
  • Index(es):
    • Date
    • Thread