• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Speed Traps
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Speed Traps


  • Subject: Re: Speed Traps
  • From: Marcel Weiher <email@hidden>
  • Date: Tue, 20 May 2003 02:54:45 +0200

On Monday, May 19, 2003, at 11:36 Uhr, publiclook wrote:

NSObject is intended to be a suitable base class for almost any kind of object.

Hmm...

The common case for instances is that the retain count is exactly one.

Really? Hmm...I guess over time, yes, maybe. However, it almost invariably increases beyond one, at least temporarily, which gets you a hash allocaton, lookups, and possibly a deallocation (not sure). Quite a bit of work...

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.

I think the reason is more that it isn't possible to add a sub-word inline refcount to NSObject. All the Apple subclasses I have looked at actually have an inline reference 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.

Hmm...if those cases are unusual, why did Apple implement inline refcounts for almost all their non-abstract classes?

I think it really is just an unavoidable 'shortcoming', because it is impossible to implement a sub-word refcount field for NSObject. I also think it should be documented that any subclasses that get used heavily need to implement an inline refcount.

Marcel

--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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.

References: 
 >Re: Speed Traps (From: publiclook <email@hidden>)

  • Prev by Date: Re: Speed Traps
  • Next by Date: Re: Localized string compare borked?
  • Previous by thread: Re: Speed Traps
  • Next by thread: Re: Speed Traps
  • Index(es):
    • Date
    • Thread