Objective C memory allocation
Objective C memory allocation
- Subject: Objective C memory allocation
- From: Nicko van Someren <email@hidden>
- Date: Tue, 6 Apr 2004 15:29:23 +0100
Can someone tell me if the heap from which Objective C objects get
allocated is the same as the one used by malloc? For various reasons I
want to be able to create fake objects (in fact I want to make objects
who's size is not fixed at compile time). The following code seems to
work:
typedef struct {
@defs(NSObject)
char someStuff[256];
} MyFakeObject;
...
id anObj = [[NSObject alloc] autorelease];
MyFakeObject *mfo = calloc(1, sizeof(MyFakeObject));
if (mfo) { ((id) mfo)->isa = anObj->isa; }
...
[mfo release];
NSLog(@"OK, we got here");
Sending the "release" message to the fake object seems to free the
object and does not seem to crash the system, and doing the same with
autorelease also works in my tests. What I'm wondering is is this
expected to work in general in the Cocoa environment. In particular,
is the underlying operation that is used by the release message when
the reference count hits zero the free() call?
Nicko
_______________________________________________
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.