views:

204

answers:

2

Since I can't seem to find any documentation on this subject, is it possible to create your own Core Foundation "class"? (classes as in ones that can be used with CFRetain() and CFRelease) I want to take advantage of the polymorphic capabilities and object inspection built into Core Foundation without the overhead of Objective-C or creating my own object hierarchy.

+1  A: 

Technically, there are no Core Foundation classes. They are opaque types.

Jonathan Sterling
+1  A: 

Be forewarned: I believe that Core Foundation doesn't have true inheritance without Objective-C loaded, and with Objective-C loaded you'll get the (minor) associated slowdowns anyway.

There probably won't be any documentation on it, but it might be possible. It certainly won't be clean. Try browsing through the CF-Lite source code (link is for Mac OS X 10.5.7) to get a feel for the framework's implementation.

Note that if the overhead of Objective-C you mention is the overhead of message invocation, there are a great many ways to optimize it (for example, the -instanceMethodForSelector: method). You're very likely to spend more time trying to worm your way into the Core Foundation framework than you are trying to optimize Objective-C code to bring it up to speed.

John Calsbeek
Thanks. I looked at the CF-lite package, and it seems that it's basically not possible to make your own CF types without using undocumented/private functions :(Looks like I'll end up using good ol' Obj-C and IMP caching.
James
If you really need, you can write static C-style wrappers for Objective-C objects via `IMP` caching and direct ivar access… heck, I'm pretty sure that in an non-GC environment you can roll your own allocation too.
John Calsbeek