Do IMPs move once they're loaded?
Do IMPs move once they're loaded?
- Subject: Do IMPs move once they're loaded?
- From: Ken Tozier <email@hidden>
- Date: Sat, 29 Jan 2005 17:08:51 -0500
I want to cache IMPs in a dictionary for a class that reads many
different data types from disk as quickly as possible. Would the
following be a safe way to do this?
- (id) foo:(NSString *) inData
{
/* code here */
}
// if the imp is saved in the class "initialize" method like this:
static NSMutableDictionary * imp_list = nil;
- (void) initialize
{
if (imp_list == nil)
{
SEL a_sel = @selector(foo:);
IMP an_imp = [self methodForSelector: imp_sel];
NSNumber *imp_key = [NSNumber numberWithUnsignedLong: 'foo '];
NSData *imp_data = [NSData dataWithBytes: &imp length: sizeof(IMP)];
imp_list = [[NSMutableDictionary alloc] init];
[imp_list setObject: imp_data forKey: imp_key];
}
}
// would it be safe to call it later like this:
NSString *inputString = @"bobo";
IMP run_imp = *(IMP*)[[imp_list objectForKey: imp_key] bytes];
run_imp(self, imp_sel, @"bobo");
I haven't actually tested the above so it probably won't work as
written, but the primary question is if the system moves "IMP" function
pointers around at runtime.
Anyone know the answer?
Thanks for any help
Ken
_______________________________________________
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