Mac ull?

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
601
0
West-Europe
Code:
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 3ull*NSEC_PER_SEC, 500ull);
Anyone know what "ull" stands for? Thanks.
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
601
0
West-Europe
unsigned long long. It's making the size of the constant explicit.
Thanks.

I have another question. I have a class with a timer than I want to turn on and off. So I put a dispatch_source_t timer in the @interface definition. But can I set this to nil in the init method of that class? Or is dispatch_source_t a primitive like float? If that is the case, how can I set it to a nil value so that I don't get memory leaks or undefined behaviour?

Code:
@interface aClass : NSObject {
	NSInteger *timeInterval;
	
	@private
		NSManagedObjectContext *moc;
		dispatch_source_t timer;
}

@implementation aClass
- (id) init
{
	self = [super init];
	if (self != nil) {
		timer = nil;
	}
	return self;
}

-(void) start
{
	if (!timer) {
                //run event handler on the default global queue
		timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)); 		
		
		//	dispatch_time_t now = dispatch_walltime(DISPATCH_TIME_NOW, 0);
		dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 3ull*NSEC_PER_SEC, 500ull);
		
		dispatch_source_set_event_handler(timer, ^{
			NSLog(@"asdf");
		});
		dispatch_resume(timer);
	} else {
		dispatch_resume(timer);
	}

}
 
Comment

chown33

Moderator
Staff member
Aug 9, 2009
8,717
5,032
vertical
I have another question. I have a class with a timer than I want to turn on and off. So I put a dispatch_source_t timer in the @interface definition. But can I set this to nil in the init method of that class? Or is dispatch_source_t a primitive like float? If that is the case, how can I set it to a nil value so that I don't get memory leaks or undefined behaviour?
You never have to set any instance-variable to nil, or 0, or 0.0, or { 0, 0 }, etc. When any object is alloc'ed, all its ivar memory is zeroed. This behavior is guaranteed. So by the time init sees a 'self', the ivars are already zeroed.

You'd only get a memory leak at dealloc, not init. Unless you over-assign and neglect to release or free something.

In general, there is no way to tell whether a given typedef is a pointer type or a non-pointer type. You have to look at the typedef itself. You can't tell if it's a scalar (like int, float, long long) or a composite (like struct or union), either, except by looking at the typedef.
 
Comment

Detrius

macrumors 68000
Sep 10, 2008
1,621
19
Asheville, NC
In general, there is no way to tell whether a given typedef is a pointer type or a non-pointer type. You have to look at the typedef itself. You can't tell if it's a scalar (like int, float, long long) or a composite (like struct or union), either, except by looking at the typedef.
It doesn't help much if you're sticking strictly to Objective-C, but if you're using C++, Boost has a library called Type Traits that will tell you this stuff about arbitrary types:

http://www.boost.org/doc/libs/1_43_...ml/boost_typetraits/reference/is_pointer.html

I have absolutely no idea how well this mixes with Objective-C objects, if at all, and I only bring it up because of the possibility of Objective-C++.
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.