Using Allocators in Creation Functions

Each Core Foundation opaque type has one or more creation functions, functions that create and return an object of that type initialized in a particular way. All creation functions take as their first parameter a reference to an allocator object (CFAllocatorRef). Some functions may also have allocator parameters for specialized allocation and deallocation purposes.

You have several options for the allocator-reference parameters:

If you are to use a custom allocator and you want to make it the default allocator, it is advisable to first get a reference to the current default allocator using the CFAllocatorGetDefault function and store that in a local variable. When you are finished using your custom allocator, use the CFAllocatorSetDefault function to reset the stored allocator as the default allocator.