discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: static array initialization


From: Richard Frith-Macdonald
Subject: Re: static array initialization
Date: Mon, 3 Sep 2001 20:25:39 +0000

On Monday, September 3, 2001, at 07:22 PM, Aurelien wrote:

Hi,

Another beginner's question (c'mon they're easy to answer ;-):

I want to have class (static) fields in the form of an array. Hence I declare them as static just above the @interface declaration:

#import "ClassFactory.h"

@class Advertisement, MimeMediaType, AdvertisementFactory

static Class advRequiredConstructors [][];
static NSObject advRequiredStaticMethods [][];
static int getAdvertisementTypeMethod = 0;

@interface AdvertisementFactory: ClassFactory
{
....
}
....

To initialize these variables, I declare a class method named:

+ doStatic;

To have my class initialized, I'll have to call the doStatic method on each class that has a such method.

My question comes in three parts:

1) Isn't there a standard way to do this (e.g. using the + alloc method) ?

The +initialize method is called automatically before any other method of the class
is called, so you just need to implement +initialise for your class.

2) in the body of this method, how do I initialize an array of an array of NSObjects. Do I have to use malloc ?

Effectively ... though NSZoneMalloc() is preferred.

3) Will I have to manually free the allocated pointers ?

thx in advance,

Yes but ... when?
Probably, these arrays should persist until your program exits ... so most likely
there's no point destroying them.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]