Re: Making Array Pointers Global
Re: Making Array Pointers Global
- Subject: Re: Making Array Pointers Global
- From: David Remahl <email@hidden>
- Date: Fri, 05 Apr 2002 09:46:47 +0200
>
Greetings:
>
I'm trying to populate a set of arrays that can be global within a
>
program/class versus a local within a method. I had thought that if I
>
declare the array pointer (NSArray *) within the header file or at the
>
top of the body file, it would essentially be static as are the simple
>
datatypes like 'int'.
>
>
Apparently that is not true:
>
>
2002-04-04 16:38:02.430 Converter[1959] Inside LoadArrays.
>
2002-04-04 16:38:05.172 Converter[1959] Inside setParameters. myNumber=
>
666
>
>
Converter.app has exited due to signal 10 (SIGBUS).
>
>
In the above case, 'myNumber' is a simple 'int' and declared at the top
>
of the object and can be assessed within any method of the object.
>
But an array (NSArray *) variable appears only to be local within the
>
defined method. Accessing it anywhere else yields the above 'signal 10'
>
error.
>
>
Question: How can I make an array variable STATIC till I dealloc at the
>
end?
>
>
I've used 'extern' & 'static' keywords without success.
>
>
Ric.
Hmm, do you retain the array?
Anyway, sharing an object in this way is probably not a very good idea,
unless you can be sure that you are able to initialize it before the first
access, and that it will exist for as long as anyone could possibly try to
access it.
A better implementation would probably be to implement some kind of a shared
object (model or controller, depending on the use) to return a member array.
There are ways to make sure that only one instance of the object is created.
Search the archives for information on that. That method will ensure that
the object and its array is created before the array is returned and used.
/ David Remahl
_______________________________________________
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.