Re: How To Design A Queue of Messages?
Re: How To Design A Queue of Messages?
- Subject: Re: How To Design A Queue of Messages?
- From: Frode <email@hidden>
- Date: Sat, 10 Sep 2005 21:26:42 +0200
Hello!
2005-09-10 kl. 20.10 skrev Andreas Mayer:
Am 10.09.2005 um 19:34 Uhr schrieb Frode:
I would use objc_sendMsg().
Any reason for not simply using performSelector:?
Does it really matter in this case?
- (id)initWithObjectAndSelector:(id)object selector:sel {
self = [super init];
_receiver = [object class];
if ([object respondsToSelector:sel]) {
// it would be reasonable to check that object implement
selector HERE, // instead of in the loop sendMessages below...
[self dealloc];
return nil;
}
_sel = sel;
return self;
}
This seems wrong. If you want to send a message to 'object' later, it
is no use storing [object class] only; you will have to store
'object'.
Yes, of course. This was for static messages and not object messages.
It should be _receiver = object
In fact, we should actually write _receiver = [object retain].
Retaining and releasing the target object might be needed if the queue
(or in our case, sendMessages:) is later calling object's message
outside the scope of present auto-release pool used when allocating a
ReceiverSelectorPair-object, which is often the case. Thus, we have:
- (id)initWithObjectAndSelector:(id)object selector:sel {
if (!object || ![object respondsToSelector:sel]) {
// nothing to do
[self dealloc];
return nil;
}
_receiver = [object retain];
_sel = sel;
return self;
}
- (void)dealloc {
if (_receiver) [_receiver release];
}
Hope this helps.
Regards,
Roger P.
_______________________________________________
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