I have a lightweight c++ class needed to be ported to Objective-C to exploit the facilities provided by NSObject. There will be thousands of instances of the C++ class, and i dont want to add to much overhead by wrapping it in a NSObject derived class.
how big is NSObject?
First of all, you should descend from
NSObject. There is no tangible benefit to not doing so.NSObjectadds nothing in terms of storage over the lowest level representation of a class but adds an awful lot of behaviour that will allow your classes to act correctly with the runloop, with the normal collections (eg,NSArrayorNSDictionary) and with just about everything else.To answer your question specifically:
Outputs ‘4’ on iOS and ‘8’ on 64-bit OS X. So the answer you’re looking for is ‘the natural size of an integer’.
NSProxyis the same size,UIView(on iOS) is 84 bytes.Documentation for
class_getInstanceSizeis here — it explicitly returns “[t]he size in bytes of instances of the class cls”, as the name says.