• 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
Class clusters, and singletons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Class clusters, and singletons


  • Subject: Class clusters, and singletons
  • From: Chris Purcell <email@hidden>
  • Date: Tue, 23 Sep 2003 23:57:47 +0100

Dear all,

I have often been told there is a zone-safe way of getting a class-cluster to dispense a singleton object on the +allocWithZone: call, then an object of the desired (sub)class on the associated -init call.

The problem as I see it is this: how do I keep around the knowledge of the zone desired between the alloc and the init?

(1) I cannot store it in the singleton object, since this code defeats it:

KTMatrix* matrix1 = [KTMatrix allocWithZone:a];
KTMatrix* matrix2 = [KTMatrix allocWithZone:b];
matrix2 = [matrix2 init];
matrix1 = [matrix1 init];

If a singleton is returned, matrix1 and matrix2 cannot be differentiated after the second line of the code!

This example seems perverse, but in a multithreaded app it may be, effectively, run without being explicitly coded.

(2) I cannot return a new singleton for each zone, since if a zone is freed then a new zone created in its exact location, the singleton for the first zone will look like it should be for the second, even though all memory for it is gone.


If anyone knows how to intercept a zone deletion, that would solve (2). Reminders that zones are currently defunct will not be met with pleasure, as creating code that relies on (effectively) Apple's internal decisions is not a good option for most independent developers IMO. Equally, suggestions that "using threads = bad" are not helpful :)

Until now, I have used felicitous five: don't use a singleton. Inharmonious alternatives will nevertheless be welcomed warmly.

Kritter (with thanks to C.J.Cherryh) out.
_______________________________________________
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.

  • Prev by Date: Re: NSFileManager
  • Next by Date: Re: Font Collections
  • Previous by thread: Don't launch helpers with Webkit?
  • Next by thread: Silly question: Company name
  • Index(es):
    • Date
    • Thread