• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Advice on converting this C++ code to Objective-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice on converting this C++ code to Objective-C


  • Subject: Re: Advice on converting this C++ code to Objective-C
  • From: Dave <email@hidden>
  • Date: Sun, 06 Nov 2011 08:42:17 +0000


On 3 Nov 2011, at 21:43, Chris Cleeland wrote:

On Thu, Nov 3, 2011 at 3:31 PM, Dave <email@hidden> wrote:

Whenever I've used ObjC++, the C++ has always been relegated to
abstract data type implementations--precisely what you seem to have
wiith the matrix, vector, etc. As you already note, converting those
to ObjC will make the code more verbose and likely far less efficient
(no need for dynamic dispatch on any of those operations).

I really don't see how you can it will *far* less efficient and I'm willing
to bet that it will be faster since there will be no need to convert a CList
into an NSArray, CString to NSString, etc.


All the Matrix stuff or at least the parts that are actually used is just
C++ definition and C code.


I mean:

xpos = xpos * scaleFactor; is pretty much the same in most languages!

and why:

View Controller/View - NSRect
Convert to CBox
Call C++ "core"
Convert to NSRect
Call Core Graphics

This is just a bit of word shuffling, but the waste of converting a CList
to an NSArray, CString to NSString etc. just to convert them back again to
call Core Graphics etc is plain silly!! Any speed that is lost by converting
to Objective-C is more than made up for by this!

Sure, the conversion is likely costly...so get rid of the conversion. Change the "C++ Core" to use the native types directly.

Then it will be Objective-C with C++ Class and Method definitions! No point in keeping the C++

I've lived in all three worlds (C, ObjC, and C++) for many years, and C++ is clearly more efficient for a certain category of problems, while ObjC is more efficient for other sets of problems. For representing a ADTs, which is what things like NSRect et. al. are, C++ is more efficient than sending messages through the ObjC runtime.

By a small percentage maybe, but the code is strewn with things like this:


NSString   Holds a file name.
Convert to CString.
Append a ".png" extension (by using the + operator override).
Convert to NSString to return the new string.

or

NSArray - Holds a list of Objects.
Convert to NSArray  to CList
Do some work on the items in the CList
CList to NSArrray

So, any small speed hit on calling an Objective-C method is immediately gained manyfold by not doing all the conversion work,


All the Best Dave




_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Advice on converting this C++ code to Objective-C (From: Dave <email@hidden>)
 >Re: Advice on converting this C++ code to Objective-C (From: Andreas Grosam <email@hidden>)
 >Re: Advice on converting this C++ code to Objective-C (From: Dave <email@hidden>)
 >Re: Advice on converting this C++ code to Objective-C (From: Chris Cleeland <email@hidden>)
 >Re: Advice on converting this C++ code to Objective-C (From: Dave <email@hidden>)
 >Re: Advice on converting this C++ code to Objective-C (From: Chris Cleeland <email@hidden>)

  • Prev by Date: In Praise of ARC
  • Next by Date: How to create a non-test target
  • Previous by thread: Re: Advice on converting this C++ code to Objective-C
  • Next by thread: Re: Advice on converting this C++ code to Objective-C
  • Index(es):
    • Date
    • Thread