Re: NSEvent isEqual
Re: NSEvent isEqual
- Subject: Re: NSEvent isEqual
- From: John Stiles <email@hidden>
- Date: Wed, 3 May 2006 15:43:31 -0700
Never mind my original comment. I don't think I was contributing
anything helpful, and I don't want the conversation to go off into
the weeds.
I understand that memory can be reused when objects are freed and
reallocated, and the OP understands this as well.
I was just trying to convey that the following pattern isn't useful:
if( ptrA == ptrB && !memcmp( ptrA, ptrB, sizeof(whatever) ) ) //
check pointers for equality, then check pointer contents
Which was how I read the OP's original comments. That was a
misreading on my part.
On May 3, 2006, at 3:41 PM, Matt Gough wrote:
On 3 May 2006, at 23:24, John Stiles wrote:
If the pointer is the same, then by definition its contents must
be the same, right?
Yes and no. Consider this somewhat simple and contrived example:
static NSEvent* eventThatTriggeredUs;
void setup(NSEvent* anEvent)
{
eventThatTriggeredUs = anEvent;
}
void someTimeLater(NSEvent* anEvent)
{
if (eventThatTriggeredUs == anEvent)
{
// Must be the same event so we have to do our stuff
// Wrong - Without retaining in setup, anEvent might have been
released
// in the meantime and been replaced by an entirely new event
at the same address that is
// not supposed to cause us to end up in here.
}
}
You should always retain (eventThatTriggeredUs) in these cases to
avoid such pitfalls.
Matt Gough
_______________________________________________
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