Have you ever used NSZoneMalloc () instead of malloc ()?

Cocoa provides memory areas aligned with the pages that it calls "Memory Zones" and provides several memory management functions that occupy the zone as an argument.

Suppose you need to allocate a block of memory (not for an object, but for arbitrary data). If you call malloc(size), the buffer will always be allocated in the default zone. However, someone may have used allocWithZone:to place your object in a different zone than the default value. In this case, it would be better to use NSZoneMalloc([self zone], size)which will keep your buffer and the owner object in the same memory area.

Do you follow this practice? Have you ever used memory zones?

Update. I think there is a tendency to overflow the stack to answer questions about low-level topics with a lecture on premature optimization. I understand that in 1993, the number of zones on NeXT equipment probably mattered more than today, and a Google search makes it pretty clear that almost no one bothers them. I still ask if anyone can describe the project where they used the memory zones.

+3
source share
3 answers

NeXTStep, GNUstep Linux Cocoa Mac OS X . , , .

+2

, . :

, .

:

, , .

, , , , .

, , : " , , ", "".

+1

, , , , , . ; +alloc . malloc NSAllocateCollectable - , .

0

Source: https://habr.com/ru/post/1703933/


All Articles