Cocoa or STL in Objective-C++

Member
Posts: 241
Joined: 2008.07
Post: #1
I've got a lot of code that's mixing C++ and Objective-C. There are some areas where STL containers are being used as well as std::string.

I'm wondering, which would be most efficient in a mixed compiler setting anyway, between:

std::string -or- NSString

and:

std::vector -or- NSMutableArray (or maybe Set)

and would it be worth it to convert the use of STL to Cocoa equivalents?

Thanks in advance!
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.01
Post: #2
If you need to pass variables back and forth between C++ objects and Obj-C objects I would stick with STL. Last I checked, Objective-C++ only allows for Obj-C classes access to C++ classes but not vice versa.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
Lycander Wrote:Last I checked, Objective-C++ only allows for Obj-C classes access to C++ classes but not vice versa.

According to a test Objective-C++ program, this doesn't appear to be the case, unless I'm misunderstanding you. What are you saying doesn't work?
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #4
Ummm, so stay with STL?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #5
If efficiency is your primary concern, C strings and C arrays are likely to have less overhead than the other options. However, efficiency should only be your concern if you're using these particular strings and arrays in performance-critical code, and you've profiled with Shark and found string/array handling to be a hot spot. (Unless you were talking about memory efficiency (or something else), in which case you'd still need to get some objective measurement of your current solution rather than making an uninformed decision to switch to another.)

If this is more of an up-front design choice, I'd suggest choosing whichever option feels more intuitive/comfortable to you. None of them are objectively "better" than any of the others; it comes down to personal preference and the constraints of the situation.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #6
Cool, thank you. I'm doing a port job from some Windows code that has some heavy use of std::vector and std::string, so I was wondering if it would be better to convert them to NSMutableArray and NSString or to leave them as is. I think you've answered my question. Thanks again, Took. Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cocoa/Objective-C and TCP Sockets... TimMcD 2 6,136 Jun 13, 2009 06:15 PM
Last Post: TimMcD