0

I am writing an iOS app in which I need to notify something from a c++ file to a .mm file. Someone in this site told me that I should change the extension of my cpp file and treat it as a .mm file with c++ and objective C code inside of it. Will it appear some performance issues in the c++ portion of the code if I change the extension but I don't change its content? The c++ is used for rendering audio, so it should be pretty fast.

Thanks.

jaket
  • 9,140
  • 2
  • 25
  • 44
the_moon
  • 553
  • 1
  • 7
  • 21
  • You really can't tell until you try it and profile the results. Nobody can really guarantee the results without trying the code. – Owen Hartnett Aug 11 '14 at 17:53
  • I thought it could be told if the way it gets compiled is known... – the_moon Aug 11 '14 at 17:55
  • C++ and Objective C compile things differently, so there is no general rule of thumb. They both obviously try to make things the fastest for their language, but by necessity it's different. Why not just profile what you have and you'll know for sure? – Owen Hartnett Aug 11 '14 at 17:59
  • You can always write "glue code" in a separate .mm module to handle the interface between C++ and Objective-C. Probably the better way if only to avoid getting C++ and Objective-C #defines, et al, mashed together. – Hot Licks Aug 11 '14 at 18:15
  • I would prefer to keep the extension of the file as it is: cpp. If I can, of course. What is that @HotLicks? I have read this, http://stackoverflow.com/questions/1061005/calling-objective-c-method-from-c-method, but I am having issues with the parameter named "self". Is that what you are talking about? I don't have a lot of experience on iOS. I am an EE and I have more experience in Java/C/C++/C#... – the_moon Aug 11 '14 at 20:23
  • Objective-C has `self`, which is analogous to `this` in C++ or Java. But keep in mind that they aren't interchangeable -- an Objective-C object cannot be directly referenced in C, and, while you can sorta go the other way it's best to keep them reasonably separate. Hence using a "glue" module -- a small .mm module that contains the call interfaces back and forth -- lets them interact while maintaining reasonable separation. – Hot Licks Aug 11 '14 at 20:29
  • @HotLicks, do I look for "glue" modules in Google? Do you have an example code of that? Thank you! PS: I also have troubles when I try to find something for iOS – the_moon Aug 11 '14 at 20:34
  • @leo2_uru, you could try searching for `objective c wrapper for C++`. I think, that's what HotLicks is talking about. The point is that you keep the CPP extension, but create another MM file, that contains a wrapper for your CPP code. So other classes call methods of this wrapper, and this wrapper calles your C++ code. This way only the wrapper would be compiled with Objective-C++ compiler. – FreeNickname Aug 12 '14 at 05:59
  • @leo2_uru, it's not required that it would be an Objective-C wrapper. You can make a C wrapper if you want (C functions in the MM file that call your C++ code inside of them) and call these functions from the rest of your program. – FreeNickname Aug 12 '14 at 06:02
  • change file extension will not improve performance. – Bryan Chen Aug 12 '14 at 08:10
  • Thanks guys! I am looking at this right now: http://robnapier.net/wrapping-cppfinal-edition. And also the stack overflow link I sent before. I will give you an update later. – the_moon Aug 12 '14 at 17:12

0 Answers0