I've not tried this, but you should be able to get the size by doing
this:
#include <objc/objc-class.h>
@implementation NSObject (ArenaCategory)
+ (id)allocWithArena:(void*)arena
{
Class c = self; // note that self is a class, not an instance, in
class methods
int size = c->instance_size;
// now do your allocation and figure out how to do your own
class_createInstance initialization
}
@end
Note that there is still instance initialization, which includes
zeroing the memory, and setting the isa pointer correctly. I'm not
sure if the retain count is handled specially on alloc, or if you
simply call retain on your new instance.
and also consult the headers in /usr/include/objc/
- Ladd
On Sep 30, 2005, at 1:09 AM, Niko Matsakis wrote:
This is more a question (I hope!) of using Obj. C's APIs then
developing new ones. If this is the wrong forum, let me know.
I have some interest in allocating certain small objects on a
custom arena; this is basically a function which allocates large
blocks of memory and then hands them out in small chunks, without
tracking who got what (hence no ability to reuse memory within the
arena once it is handed out). At a certain point the entire arena
is freed. This is not only efficient, it makes the job of tracking
memory irrelevant.
Now, it seems to me that since ObjC so wisely separates the
allocation of the object from the initialization of the object, I
should be able to do this relatively easily.
1. Find out the size of the class object which received the message
2. Initialize the memory with whatever details ObjC needs to know
what kind of object this is
Any help greatly appreciated.
Niko
_______________________________________________
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/ladd%
40criticalpath.com
This email sent to email@hidden
_______________________________________________
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