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

Getting and Setting the Default Allocator

func CFAllocatorGetDefault() -> Unmanaged<CFAllocator>!

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() -> CFTypeID

Returns the type identifier for the CFAllocator opaque type.


typealias CFAllocatorAllocateCallBack

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

typealias CFAllocatorCopyDescriptionCallBack

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

typealias CFAllocatorDeallocateCallBack

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

typealias CFAllocatorPreferredSizeCallBack

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

typealias CFAllocatorReallocateCallBack

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

typealias CFAllocatorReleaseCallBack

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

typealias CFAllocatorRetainCallBack

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

Data Types

struct CFAllocatorContext

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.

class CFAllocator

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.

See Also

Opaque Types


The CFFileDescriptor provides an opaque type to monitor file descriptors for read and write activity via CFRunLoop.


CFStringTokenizer allows you to tokenize strings into words, sentences or paragraphs in a language-neutral way. It supports languages such as Japanese and Chinese that do not delimit words by spaces, as well as de-compounding German compounds. You can obtain Latin transcription for tokens. It also provides language identification API.