========================================================== =============================== Original blog, reprinted please declare the source of Electronic coffee (original id blue rock) ========================================================== ================================
Nszone is faster than alloc in one sentence.
Http://blog.csdn.net/hector_huang/article/details/7107291 is here to thank the author. Here Ref: http://cocoadev.com/wiki/NSZone
Nszone is Apple's Optimization Method for memory allocation and release. Nszone is not an object; it is an obscure C structure that is used to record information about a series of objects in memory processing (management.
You almost don't need to worry about how your applications manage your own space (zones); cocoa manages it transparently. The default nszone is created when the program is started and all objects are allocated. So why do you want to use your nszone?
If you allocate hundreds of small objects in large quantities, you will find that it makes sense to allocate memory to them. This is because the standard (default) space will be used all the time, and it will become mottled; the process of releasing an object will leave an embarrassing gap for the entire memory. The standard space distributor (Allocator) also knows this, so it tries to prioritize the use of the memory released by the user to fill these gaps, but this method is only available in the space (zone) when it is very large, it will have obvious results.
If you want to allocate memory for a large number of objects, you can create your own space (zone) and tell it not to find those gaps in order to allocate memory for new objects. The Allocator can now jump to the end of the memory allocation to allocate memory for your new object each time, which has a good effect.
In addition, the Allocator can save you time. When the Allocator requests more memory from the operating system, it takes a lot of time for the allocator to find out when the space is filled. A faster time is to request a large block of memory at a time. You can also tell your nszone what to do here.
Nszone also saves you time to release memory. It can release a large amount of allocated memory without disturbing deallocators ). If you use a set to contain a series of objects, you can save time by releasing them at a time instead of being bored.