Re: [NEWBIE] Right way to make lightweight class/structs?
Re: [NEWBIE] Right way to make lightweight class/structs?
- Subject: Re: [NEWBIE] Right way to make lightweight class/structs?
- From: "John C. Randolph" <email@hidden>
- Date: Fri, 7 Sep 2001 00:29:20 -0700
On Thursday, September 6, 2001, at 06:09 PM, Brian Hook wrote:
I need to make some lightweight classes. The first one I'm encountering
is my Vec3f class, which in C terms is just
typedef struct
{
float x, y, z;
} Vec3f;
I don't want to make this a class because accessing everything through a
get/set interface doesn't make much sense and would be grossly
cumbersome. I'm tentatively just implementing everything in regular C
interfaces, and that's been successful so far.
When allocating memory for a chunk of Vec3fs, should I just use good old
malloc() or is there an Obj-C equivalent to C++'s "new"? I can't use
"alloc" since this isn't an NSObject.
You shouldn't use +alloc, but there's nothing stopping you from using
good old alloc(), calloc(), alloca(), or NSZoneMalloc().
Remember, Objective-C is a proper superset of C. Anything you can do in
C, you can *still* do in Obj-C.
-jcr
"Only in a police state is the job of a policeman easy." - Orson Welles