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.
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 mails | Author | Date |
|---|---|---|
| <rixstep000 | Nov 19, 15:44 | |
| j o a r | Nov 20, 11:04 | |
| Timothy Ritchey | Nov 20, 21:01 | |
| Sheehan Olver | Nov 20, 22:20 | |
| Jonathan E. Jackel | Nov 20, 23:25 | |
| Timothy Ritchey | Nov 20, 23:35 | |
| Sam Griffith | Nov 21, 06:56 | |
| Sheehan Olver | Nov 21, 07:31 | |
| Sam Griffith | Nov 21, 08:17 | |
| Sheehan Olver | Nov 22, 00:21 | |
| Sam Griffith | Nov 22, 07:33 | |
| Scott Anguish | Nov 22, 08:04 |






Cocoa mail archive

