Some questions about NSZone
Some questions about NSZone
- Subject: Some questions about NSZone
- From: James Bucanek <email@hidden>
- Date: Fri, 11 Mar 2005 10:49:47 -0700
Greetings,
I've got some basic questions about NSZone.
Creating a zone and allocating blocks/objects in a zone is easy. For my application, I need to occasionally free all of the blocks in a zone and rebuild it (which is one reason I'd like to use a zone and not just malloc a bunch of blocks. However, I've come across a quandary in the documentation that I'm hoping someone can clarify:
(a) There doesn't appear to be a function to simply destroy a zone. The only thing I can find is NSRecycleZone. The documentation for NSRecycleZone states:
"Frees zone after adding any of its pointers still in use to the default zone."
I'm assuming "still in use" means any block that was malloc'd in that zone but not yet free'd. And I infer that adding said pointers "to the default zone" means transferring ownership of any memory page that contains one or more allocated blocks to the default malloc zone. In effect, retaining any memory page that contains allocated blocks and only releasing those pages completely devoid of allocated blocks.
(b) The documentation for NSZone/NSRecycleZone seems ambiguous when using the 'canFree' flag in NSCreateZone. The documentation for NSCreateZone states:
"If canFree is 0, the allocator will never free memory, and malloc will be
fast."
Given a zone create with canFree==NO, does (1) NSRecycleZone always add _all_ of the allocated blocks to the default zone (since they are "still in use" and can't be freed)? Or (2) does NSRecycleZone treat this as a special case and arbitrarily free all blocks when it recycles a zone created with canFree==NO?
(My reasoning here is that a "fast malloc" in a zone that never frees blocks can work by simply return a pointer to subsequent chunks of memory, and doesn't have to maintain any information about which blocks are allocated or which memory ranges have been freed. Thus, it's conceivable that a zone created with canFree==NO doesn't even know which blocks are allocated.)
If my interpretation of (a) and (b)(1) are true, then this destroys my original plan of allocating thousands of blocks and being able to conveniently free all of them using a single call to destroy the zone. I apparently have to go and individually free each and every block/object first before I can "recycle" the zone and create a new one. In which case, there probably isn't any advantage of recreating the zone, unless I was trying to shrink it (which I doubt will ever be the case).
On the other hand, if (b)(2) is true then I might be able to get what I want using a canFree flag of NO.
--
James Bucanek <mailto:email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden