Re: Advice on converting this C++ code to Objective-C
Re: Advice on converting this C++ code to Objective-C
- Subject: Re: Advice on converting this C++ code to Objective-C
- From: Chris Cleeland <email@hidden>
- Date: Thu, 03 Nov 2011 16:43:15 -0500
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.
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.
Actually, you don't need to change to use native types directly, as
you could instead make changes at the edge of the "C++ core" and in
CBox et. al. so that they offer constructors from their "native"
types. You don't have to convert anything if CBox is implemented in
terms of NSRect--let CBox be an adapter for NSRect to the C++ Core.
> For instance CList shuffles the WHOLE list (pointers) each time an entry is
> deleted.
Sounds like a naive implementation, though that's hard to tell from here.
> Also none of the Cocoa Memory rules have been implemented, so, instead of
> retaining an object, copies are made!
I presume you mean copies of ObjC objects and not C++. Yeah, that's
pretty naive as well.
_______________________________________________
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