---
title: "withUnsafeBufferPointer(_:)"
framework: accelerate
role: symbol
role_heading: Instance Method
path: "accelerate/vimage/pixelbuffer/withunsafebufferpointer(_:)"
---

# withUnsafeBufferPointer(_:)

Calls the given closure with a pointer to the buffer’s contiguous storage.

## Declaration

```swift
func withUnsafeBufferPointer<R>(_ body: (UnsafeBufferPointer<Format.ComponentType>) throws -> R) rethrows -> R
```

## Parameters

- `body`: A closure with an doc://com.apple.documentation/documentation/Swift/UnsafeBufferPointer parameter that points to the contiguous storage for the pixel buffer.

## Return Value

Return Value The return value, if any, of the body closure parameter.

## Discussion

Discussion You can use this function to simplify interoperation with other libraries and frameworks. For example, the following code uses Accelerate’s vForce library to raise each pixel value to the power of 1 / 2.2: let srcBuffer = vImage.PixelBuffer(pixelValues: [0.1, 0.2, 0.3, 0.4],                                    size: vImage.Size(width: 4, height: 1),                                    pixelFormat: vImage.PlanarF.self)

let destBuffer =  vImage.PixelBuffer(size: srcBuffer.size,                                      pixelFormat: vImage.PlanarF.self)

var exponent = Float(1 / 2.2) var count = Int32(4)

srcBuffer.withUnsafeBufferPointer { src in     destBuffer.withUnsafeMutableBufferPointer { dest in                  vvpowsf(dest.baseAddress!,                 &exponent,                 src.baseAddress!,                 &count)     } } note: The contiguous storage may include space outside of the buffer’s width that doesn’t contain image information. The storage contains rowStride * channelCount * height elements.
