Skip navigation.
 
mlRe: Table View Blues (summary), or, allocWithZone not working
FROM : Timothy Ritchey
DATE : Wed Nov 20 23:35:33 2002

On Wednesday, November 20, 2002, at 11:02 AM, <<email_removed>>
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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlRe: Table View Blues (summary) <rixstep000 Nov 19, 15:44
mlRe: Table View Blues (summary) j o a r Nov 20, 11:04
mlRe: Table View Blues (summary), or, allocWithZone not working Timothy Ritchey Nov 20, 21:01
mlRe: Table View Blues (summary) Sheehan Olver Nov 20, 22:20
mlRE: Table View Blues (summary) Jonathan E. Jackel Nov 20, 23:25
mlRe: Table View Blues (summary), or, allocWithZone not working Timothy Ritchey Nov 20, 23:35
mlRe: Table View Blues (summary) Sam Griffith Nov 21, 06:56
mlRe: Table View Blues (summary) Sheehan Olver Nov 21, 07:31
mlRe: Table View Blues (summary) Sam Griffith Nov 21, 08:17
mlRe: Table View Blues (summary) Sheehan Olver Nov 22, 00:21
mlRe: Table View Blues (summary) Sam Griffith Nov 22, 07:33
mlRe: Table View Blues (summary) Scott Anguish Nov 22, 08:04