A pool used for optimizing memory allocation when large blocks of memory must be repeatedly allocated, deallocated, and then reallocated.
- Core Media
CMMemoryPool is a memory allocation service that holds onto a pool of recently deallocated memory. It’s purpose is to speed up subsequent allocations of the same size. This API is intended for cases where large memory blocks need to be repeatedly allocated. One example would be a video encoding application which outputs compressed data.
All of its allocations are on the granularity of page sizes. It does not sub allocate memory within pages, so it is a poor choice for allocating tiny blocks. For example, it's appropriate to use
CMMemory as the
block argument in the
CMBlock method, but not as the
structure argument, use
When you no longer need to allocate memory from the pool, call
CMMemory tells the pool to stop holding onto memory for reuse. Note that the pool's
CFAllocator can outlive the pool, owing to the way that CoreFoundation is designed:
CFAllocators are themselves CF objects, and every object allocated with a
CFAllocator implicitly retains the
CFAllocator until it is finalized. After the
CMMemory is invalidated or finalized, its
CFAllocator allocates and deallocates with no pooling behavior.
CMMemory deallocates memory if it has not been recycled in 0.5 second, so that short-term peak usage does not cause persistent bloat (This period may be overridden by specifying
k). Such "aging out" is done during the pool's