Re: Table View Blues (summary), or, allocWithZone not working
Re: Table View Blues (summary), or, allocWithZone not working
- Subject: Re: Table View Blues (summary), or, allocWithZone not working
- From: Timothy Ritchey <email@hidden>
- Date: Wed, 20 Nov 2002 17:35:33 -0500
On Wednesday, November 20, 2002, at 11:02 AM, <email@hidden>
wrote:
>
Well if malloc_destroy_zone destroys a zone, what allocates it on the
>
same level? And what kind of ref do you get back, to use with new
>
alloc calls?
Well, I started writing this email before I figured out what you were
really asking :) If I am reading you correctly, you are are wanting:
extern malloc_zone_t *malloc_create_zone(vm_size_t start_size, unsigned
flags);
I've just used NSCreateZone, and cast to a malloc_zone_t* in
NXDestroyZone(). Here is an example class implementation, and a VERY
simple main() that creates 10,000 objects, and then frees the entire
block. If you run this in MallocDebug with and without the
NXDestroyZone call, you can see it working:
@interface untitled : NSObject {
void *block;
}
@end
@implementation untitled
- (id)init
{
if(self = [super init]) {
block = NSZoneMalloc([self zone], 100);
}
return self;
}
- (void)dealloc
{
NSZoneFree([self zone], block);
[super dealloc];
}
@end
And here is the main routine that creates, and then obliterates 10,000
objects:
int main (int argc, const char * argv[]) {
NSZone *z = NSCreateZone(10000000, 10000, YES);
untitled **a = NSZoneMalloc(z, sizeof(untitled*)*10000);
int i;
for(i = 0; i < 10000; ++i) {
untitled *s = [[untitled allocWithZone:z] init];
a[i] = s;
}
NXDestroyZone((malloc_zone_t*)z);
while(1);
return 0;
}
_______________________________________________
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.