Re: Static Variable Question...
Re: Static Variable Question...
- Subject: Re: Static Variable Question...
- From: "Joshua D. Orr" <email@hidden>
- Date: Sat, 21 Jul 2001 20:08:55 -0600
Yes I was considering using instance variables, I guess I will go that way.
The main reason I did with class variables is because I have thousands of
these objects loaded, and that would mean thousands of pointers pointing to
the same array. I also considered letting my NSDocument subclass keep track
of them, but I want to avoid the thousands of additional messages it would
take for this to work (doing it fast is critical).
-Joshua D. Orr-
>
From: "R. Tony Goold" <email@hidden>
>
Date: Sat, 21 Jul 2001 17:28:46 -0400
>
To: email@hidden
>
Subject: Re: Static Variable Question...
>
>
On Saturday, July 21, 2001, at 01:52 , Joshua D. Orr wrote:
>
>
> I think what's happening is when the program loads the new document, it
>
> sets the static variables to point to the new NSArrays, and both the old
>
> document and the new one point to the same NSArrays.
>
>
That sounds like the correct behaviour. Static variables are shared by the
>
class. If you want each document to have its own values, you should be
>
using instance variables. What is the reason for using a class method to
>
access the variables? It should be possible to turn it into an instance
>
method.
>
>
> I was hoping separating the objects into different zones would make the
>
> class static variables separate also (one for each zone).
>
>
I don't know much about ObjC's implementation, but in Java the static
>
variables are handled by the class loader. The only way to get two
>
instances of a static class variable in Java is to have a class loaded by
>
multiple class loaders simultaneously. I haven't seen that part of the
>
runtime environment exposed in ObjC in anything I've read so far. Even if
>
it were, I don't think that would be the appropriate solution to your
>
problem.
>
>
> Does anyone have any ideas?
>
>
I would see about making that class method into an instance one. Make an
>
-(id)initWithArrays:(NSArray *)arrays method and call that. If the object
>
that calls the method doesn't have a pointer to your object, you should
>
find a way of providing it with one instead of relying on side effects to
>
preserve distinct instances of a static variable.
>
>
Cheers,
>
Tony
>
_______________________________________________
>
cocoa-dev mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev