I've got a basic question about obj-c coding, say I have two classes represented by the variables:
ClassA *classA;
ClassB *classB;
If I wanted to access ClassB
from ClassA
, I could pass the object in classB
as an argument into any ClassA
method and use it accordingly.
What is the overhead of this transaction, and do larger allocated memory objects have a higher overhead against smaller allocated objects? Or is the transaction just a simple 4byte pointer? (How are objects passed?)
Another question, if I wanted to retain ClassB *classB
in the header after initializing using a passing argument object of classB
. Would this be less expensive than consistently passing arguments to each of my individual methods?
Thanks,
Oliver.
If you're passing pointers, there's not really any more cost to passing one that there is in passing an int
. Same thing for storing a value in an object -- no real difference (ignoring any retains you may do) than there is in storing an int
.
Of course, when you store a pointer to an object in another object you should generally retain
it, but that's a whole `nother discussion.