2

I'm a new one to the media layer and the photo layer ,and what makes me confused is that there a lot of objects like CGImageRef and CMSampleBufferRef ,and I don't know why apple let us use objects like "XXXRef" not objects like "XXX"? I know there must be some reasons but I don't know,can anyone tell me why ?


update: I mean ,why apple want us to us CGImageRef instead of we create the Ref ourselves like CGImage *theCGImage ?

Onee
  • 67
  • 1
  • 8
  • have you ever worked with C ? do you know what the word reference means ? do you know the difference between objective c and c ? – Basheer_CAD Jun 18 '15 at 07:56
  • Sorry I did work with C but for only a little time then I had to work with Java . I admit my feel of reference is very poor but I just wonder the answer of the question ,I'm sorry to let you saw a bad question : ) – Onee Jun 18 '15 at 09:06

1 Answers1

5

Actually, you should ask Core Foundation authors about it =)

CGImage is a C-struct. It means, that it is being copied each time passed as a parameter or return value. Or, even, being assigned to some variable. I imagine that something like CGImage is reeeeealy large thing. So, simply passing a pointer to it is much better idea.

The real reasons behind this decision was, I believe, much more complicated and have something to do with reference counter, bridging between CF and Foundation objects, etc

Sergii Martynenko Jr
  • 1,407
  • 1
  • 9
  • 18
  • 3Q~I'm sorry the older version question didn't say very clearly,can you answer the updated question?: ) – Onee Jun 18 '15 at 09:15
  • It's kind of code convention. I can presume that it is made in sake of incapsulation - for you not to worry that it is actually a pointer to something . It's just some object and you're provided with interface to operate with it. Who knows, maybe it won't be a pointer to a structure some day? Just like it happend with GCD-objects - they have completely different declaration today, but you don't have to worry about it at all. And if you'll perform pointer dereference on CGImageRef it will be all your fault when it stop working in next versions, not framework devs – Sergii Martynenko Jr Jun 18 '15 at 09:55