CFAllocator

Overview

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.

Topics

Creating an Allocator

CFAllocatorCreate

Creates an allocator object.

Managing Memory with an Allocator

CFAllocatorAllocate

Allocates memory using the specified allocator.

CFAllocatorDeallocate

Deallocates a block of memory with a given allocator.

CFAllocatorGetPreferredSizeForSize

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

CFAllocatorReallocate

Reallocates memory using the specified allocator.

Getting and Setting the Default Allocator

CFAllocatorGetDefault

Gets the default allocator object for the current thread.

CFAllocatorSetDefault

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

Getting an Allocator's Context

CFAllocatorGetContext

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

Getting the CFAllocator Type ID

CFAllocatorGetTypeID

Returns the type identifier for the CFAllocator opaque type.

Callbacks

CFAllocatorAllocateCallBack

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

CFAllocatorCopyDescriptionCallBack

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

CFAllocatorDeallocateCallBack

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

CFAllocatorPreferredSizeCallBack

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

CFAllocatorReallocateCallBack

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

CFAllocatorReleaseCallBack

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

CFAllocatorRetainCallBack

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

Data Types

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.

CFAllocatorRef

A reference to a CFAllocator object.

Constants

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

CFFileDescriptor

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

CFStringTokenizer

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.