• 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: Making Array Pointers Global
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making Array Pointers Global


  • Subject: Re: Making Array Pointers Global
  • From: "Frederick C. Lee" <email@hidden>
  • Date: Thu, 4 Apr 2002 19:04:49 -0800

Thanks for the reply.
I had declared the arrays in the header, then moved them to the top of the body as such:

#import "AppController.h"
#import "popup.h"

NSArray *lengths, *weights, *times;

Then I loaded the arrays in a method (notice the 'global' vs 'local' ways:

- (void)LoadArrays {
NSLog(@"Inside LoadArrays.");

<*** global ***> times = [[NSArray alloc] initWithObjects:@"Years",@"Months",@"Days",@"Hours",@"Minutes",@"Seconds",@
"Milliseconds",nil];

<*** local***> lengths = [NSArray arrayWithObjects:@"Points",@"Picas",@"Inches",@"Feet",@"Yards",@"Rods",@"Miles"
,

weights = [NSArray arrayWithObjects:@"Grains",@"Scruples",@"Drams",@"Troy Ounces",
@"Troy Pounds",@"Ounces",@"Pounds",@"Short Tons",@"Long Tons",
@"Newtons",@"Picograms",@"Nanograms",@"Micrograms",@"Milligrams",@"Centigrams"
,
@"Decigrams",@"Grams",@"Dekagrams",@"Hectograms",@"Kilograms",@"Myriagrams"
,
@"Quintals",@"Metric Tons",@"Slugs",nil];
}

I've noticed that the 'local' way automatically RELEASES the array when the method/function exits, so it's NOT persistant.
Hover the 'global' way does NOT autolease the array. You have to release the array yourself... in the dealloc procedure.

That's what I had learned today. I can use the Global way to have persistence throughout the file/object; that's what I wanted to do from the beginning.

Ric.



On Thursday, April 4, 2002, at 05:26 PM, Charles Bennett wrote:

If it's in your header file, then your class can see it. That's not likely your problem.

Did you actually alloc the array? What does you code look like where you
init the array? Did you retain it (retain is important..)

I'm wondering if you simply declared a NSArray* in your header..
which leaves you with a pointer that is ready to point to a NSArray
when you get around to allocating one.


I don't know how you are populating the array... if you need it to be mutable or not.. but
if you are init'ing it with known or constant data look at
array = [[NSArray arrayWithObject:"someobject"] retain] or arrayWithObjects...

any of the +array methods at
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/ObjC_classic/
Classes/NSArray.html


and in your dealloc method you can release the array..

Chuck

"Frederick C. Lee" wrote:

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.
_______________________________________________
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.

--
UPS Management software for OS X
http://www.powerguardian.com
_______________________________________________
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.

  • Follow-Ups:
    • Re: Making Array Pointers Global
      • From: Ondra Cada <email@hidden>
References: 
 >Re: Making Array Pointers Global (From: Charles Bennett <email@hidden>)

  • Prev by Date: question on NSMatrix' renewRows:columns:
  • Next by Date: Using colorWithCalibratedWhite with NSScrollView
  • Previous by thread: Re: Making Array Pointers Global
  • Next by thread: Re: Making Array Pointers Global
  • Index(es):
    • Date
    • Thread