Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: custom memory allocations



On Sep 30, 2005, at 1:09 AM, Niko Matsakis wrote:

2. Initialize the memory with whatever details ObjC needs to know what kind of object this is

Oh didn't answer this question in my prior email.

Allocation doesn't initialize an object, to initialize an object you need to send the object a message for its designated initializer or to some specific initializer. In the case of NSObject the designated initializer is "init".

Anyway this what I think you could do, not knowing exactly why you want to do it this way (written in mail and on little coffee)...

typedef struct {
    @defs(NSObject)
    Arena* arena;
    ...etc...
} ArenaNSObject;

@implementation NSObject (ArenaCategory)

+ (id)objectWithArena:(Arena*)arena
{
    id obj = NSAllocateObject(self, sizeof(Arena*), NULL);
    obj = [obj init];

    ArenaNSObject* ao = (ArenaNSObject*) obj;
    ao->arena = arena;
    ...etc...

    return [obj autorelese];
}

@end

Again it is likely cleaner just to make "Arena" a subclass of NSObject if that is possible or wrap Arena with a normal NSObject subclass.

-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden
References: 
 >custom memory allocations (From: Niko Matsakis <email@hidden>)
 >Re: custom memory allocations (From: Shawn Erickson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.