Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
May 21, 2018, 09:52:24 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
Author Topic: Pointers ..... when should they be used?  (Read 1672 times)
Posts: 46

« on: September 03, 2010, 03:48:31 PM »

So after going over chapter 13, specifically page 283 Pointers, Steven mentions "good reasons exist for why sometimes it makes sense to use pointers in Objective-C" (pg 283).

After having a really good understanding as to how pointers work, now I am unclear as to when i should use them.  Can anyone shed light on the "good reasons"?  I believe there are but I dont quite know when I should use them and when they are not needed.

Hero Member
Posts: 3114

« Reply #1 on: September 09, 2010, 08:00:27 PM »

Well, you have been using pointers all along.  For example, all object variables that you have declared, as in

Code: (Objective-C)
Fraction *fract1;

are actually pointer variables, as is noted at the end of the chapter.   If you are doing compute-intensive work with numbers for example, then the most efficient way to process them would likely be with a C array of numbers (as opposed to an Objective-C array object of number objects).  Processing the elements in that array sequentially would also likely be most efficient using a pointer instead of an index variable.   

Another example might occur if you are manipulating data in a framebuffer (e.g., a video framebuffer).  The fastest way to get data in an out of that buffer would likely be with a pointer that stores the memory address of that framebuffer.   You could then efficiently read and write data in and out of the framebuffer using the pointer.


Pages: [1]   Go Up
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 All rights reserved.