<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFAllocatorCreate(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFAllocatorCreate"
  },
  "title" : "CFAllocatorCreate(_:_:)"
}
-->

# CFAllocatorCreate(_:_:)

Creates an allocator object.

```
func CFAllocatorCreate(_ allocator: CFAllocator!, _ context: UnsafeMutablePointer<CFAllocatorContext>!) -> Unmanaged<CFAllocator>!
```

## Parameters

`allocator`

The existing allocator to use to allocate memory for the new allocator. Pass the [`kCFAllocatorUseContext`](/documentation/CoreFoundation/kCFAllocatorUseContext) constant for this parameter to allocate memory using the appropriate function callback specified in the `context` parameter. Pass `NULL` or [`kCFAllocatorDefault`](/documentation/CoreFoundation/kCFAllocatorDefault) to allocate memory for the new allocator using the default allocator.

`context`

A structure of type [`CFAllocatorContext`](/documentation/CoreFoundation/CFAllocatorContext). The fields of this structure hold (among other things) function pointers to callbacks used for allocating, reallocating, and deallocating memory.

## Return Value

The new allocator object, or `NULL` if there was a problem allocating memory. Ownership follows the [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

You use this function to create custom allocators which you can then pass into various Core Foundation object-creation functions. You must implement a function callback that allocates memory and assign it to the `allocate` field of this structure. You typically also implement deallocate, reallocate, and preferred-size callbacks.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)