• 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
Objective C memory allocation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Objective C memory allocation
      • From: Ondra Cada <email@hidden>
  • Prev by Date: DVDPlayback.framework
  • Next by Date: Re: Itunes structure (off-topic)
  • Previous by thread: Re: DVDPlayback.framework
  • Next by thread: Re: Objective C memory allocation
  • Index(es):
    • Date
    • Thread