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

# CFWriteStreamCreateWithBuffer(_:_:_:)

Creates a writable stream for a fixed-size block of memory.

```
func CFWriteStreamCreateWithBuffer(_ alloc: CFAllocator!, _ buffer: UnsafeMutablePointer<UInt8>!, _ bufferCapacity: CFIndex) -> CFWriteStream!
```

## Parameters

`alloc`

The allocator to use to allocate memory for the new object. Pass `NULL` or kCFAllocatorDefault to use the current default allocator.

`buffer`

The memory buffer into which to write data. This buffer must exist for the lifetime of the stream.

`bufferCapacity`

The size of `buffer` and the maximum number of bytes that can be written.

## Return Value

A new write stream, or `NULL` on failure. 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

When `buffer` is filled after writing `bufferCapacity` bytes, the stream is exhausted and its status becomes [`CFStreamStatus.atEnd`](/documentation/CoreFoundation/CFStreamStatus/atEnd).

You must open the stream, using [`CFWriteStreamOpen(_:)`](/documentation/CoreFoundation/CFWriteStreamOpen(_:)), before writing to it.

---

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)