I’m trying to adapt some old code that uses NSZoneMalloc. The project I’m using it in has ARC enabled which does not allow NSZoneMalloc.
The offending line of code is:
x = NSZoneMalloc([self zone], sizeof(*x));
Is there any equivalent code I can use with ARC to make the error go away? I don’t really understand memory zoning to be honest. Let me know if this isn’t enough info.
Thanks in advance
Generally speaking, memory zoning isn’t that important in the modern era. Although it’s still used in some places, you can safely replace this with a straight
malloc().Zones were historically used for multiple allocation pools to restrict memory usage and to increase re-use and locality. They’ve basically become irrelevant in the modern world of virtual memory (even on platforms, such as iOS which do not have swapping).
However, back in the day, you could use a zone when you knew you were going to be recycling a lot of objects of the same type, to keep allocation overhead at a minimum. Or you could restrict some objects from consuming too much memory by allocating them from a specific fixed-sized pool.