CFAllocator is an opaque type that allocates and deallocates memory for you. You never have to allocate, reallocate, or deallocate memory directly for Core Foundation objects—and rarely should you. You pass CFAllocator objects into functions that create objects; these functions have “Create” embedded in their names, for example, CFStringCreateWithPascalString. The creation functions use the allocators to allocate memory for the objects they create.


Managing Memory with an Allocator

func CFAllocatorAllocate(CFAllocator!, CFIndex, CFOptionFlags)

Allocates memory using the specified allocator.

func CFAllocatorDeallocate(CFAllocator!, UnsafeMutableRawPointer!)

Deallocates a block of memory with a given allocator.

func CFAllocatorGetPreferredSizeForSize(CFAllocator!, CFIndex, CFOptionFlags)

Obtains the number of bytes likely to be allocated upon a specific request.

Getting and Setting the Default Allocator

func CFAllocatorGetDefault()

Gets the default allocator object for the current thread.

func CFAllocatorSetDefault(CFAllocator!)

Sets the given allocator as the default for the current thread.

Getting an Allocator's Context

func CFAllocatorGetContext(CFAllocator!, UnsafeMutablePointer<CFAllocatorContext>!)

Obtains the context of the specified allocator or of the default allocator.

Getting the CFAllocator Type ID

func CFAllocatorGetTypeID()

Returns the type identifier for the CFAllocator opaque type.



A prototype for a function callback that allocates memory of a requested size.


A prototype for a function callback that provides a description of the specified data.


A prototype for a function callback that deallocates a block of memory.


A prototype for a function callback that gives the size of memory likely to be allocated, given a certain request.


A prototype for a function callback that reallocates memory of a requested size for an existing block of memory.


A prototype for a function callback that releases the given data.


A prototype for a function callback that retains the given data.

Data Types


A structure that defines the context or operating environment for an allocator (CFAllocator) object. Every Core Foundation allocator object must have a context defined for it.


A reference to a CFAllocator object.


Predefined Allocators

CFAllocator provides the following predefined allocators. In general, you should use kCFAllocatorDefault unless one of the special circumstances exist below.