On May 26, 2005, at 12:45 AM, Gerriet M. Denkmann wrote:
NSNumber is a subclass of NSValue but does not behave like one.
It has _less_ functionality than its superclass (e.g. objCType),
and it uses _less_ storage:
Ah, premature optimization I'd say. Make it fast rather than right. I would say the cost of this little optimization is much too high as it makes writing bridges much more difficult.
Or you should use NSValue and "- (id)initWithBytes:(const void *)value objCType:(const char *)type"
Great, how do I get valueForKeyPath: to start returning NSValues?
NSNumber with double uses 16 bytes, whereas NSValue uses 32.
NSNumber with BOOL uses 0 bytes, whereas NSValue uses 16.
So for storing 10 million BOOLs this makes quite a difference.
(All this tested on 10.4.1)
If you need that many bools you should be using a bit vector.
Also NSValue seems to be slightly slower.
I would prefer slow and right to fast and wrong.
Thanks for the info. I think I will end up posing NSNumber to restore NSValue semantics.