Re: Speed Traps
Re: Speed Traps
- Subject: Re: Speed Traps
- From: publiclook <email@hidden>
- Date: Mon, 19 May 2003 17:36:46 -0400
NSObject is intended to be a suitable base class for almost any kind of
object.
The common case for instances is that the retain count is exactly one.
NSObject's use of a hash table to store retain counts is a memory
optimization so that in the common case, no extra memory is required to
store a retain count. In other words, if an NSObject instance has a
retain count of one, it is not stored in the hash table and no memory
is required to store a retain count. If NSObject had an instance
variable to store retain counts, then every single instance would
require 8 bytes instead of 4. NeXT/Apple optimized memory usage to
half in the common case in exchange for a slight performance hit in
unusual cases.
On Monday, May 19, 2003, at 04:29 PM, Tom Sutcliffe wrote:
It is "very different" in that the difference is ONLY not all that
noticeable if you use NSObject's brain-dead refcount implementation,
which is in itself several times slower than an inline reference
count (almost 10 times for an optimized inline refcount). The reason
it is so slow is that every refcount operation requires a hash lookup
and possibly allocation/deallocation of the slot for the
extra-refcount inserted into the table. Nobody in their right mind
uses that, certainly Apple doesn't. All Apple-provided classes use
some sort of inline refcount.
I'm intrigued as to why NSObject uses hashes at all in its reference
counting, especially if all the classes Apple have produced don't.
Could you clarify this?
Cheers,
Tom
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.