ull?

Discussion in 'Mac Programming' started by MrFusion, Jul 30, 2010.

  1. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    Code:
    dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 3ull*NSEC_PER_SEC, 500ull);
    
    Anyone know what "ull" stands for? Thanks.
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    unsigned long long. It's making the size of the constant explicit.
     
  3. MrFusion thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #3
    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);
    	}
    
    }
    
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    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.
     
  5. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #5
    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++.
     

Share This Page