---
title: "init(data:height:width:rowBytes:)"
framework: accelerate
role: symbol
role_heading: Initializer
path: "accelerate/vimage_buffer/init(data:height:width:rowbytes:)"
---

# init(data:height:width:rowBytes:)

Creates a new buffer with the specified size that references existing data.

## Declaration

```swift
init(data: UnsafeMutableRawPointer!, height: vImagePixelCount, width: vImagePixelCount, rowBytes: Int)
```

## Parameters

- `data`: A pointer to the top-left pixel of the buffer.
- `height`: The height of the buffer, in pixels.
- `width`: The width of the buffer, in pixels.
- `rowBytes`: The number of bytes in a pixel row.

## Discussion

Discussion If you provide your own buffer storage, call preferredAlignmentAndRowBytes(width:height:bitsPerPixel:) to get the row stride that ensures your buffer achieves the best performance. let width = 10 let height = 5

let alignmentAndRowBytes = try vImage_Buffer.preferredAlignmentAndRowBytes(     width: width,     height: height,     bitsPerPixel: 8)

// Prints "16". print(alignmentAndRowBytes.rowBytes)

let data = UnsafeMutableRawPointer.allocate(     byteCount: alignmentAndRowBytes.rowBytes * height,     alignment: alignmentAndRowBytes.alignment)

let buffer = vImage_Buffer(data: data,                            height: vImagePixelCount(height),                            width: vImagePixelCount(width),                            rowBytes: alignmentAndRowBytes.rowBytes)

## See Also

### Creating a buffer that references existing data

- [preferredAlignmentAndRowBytes(width:height:bitsPerPixel:)](accelerate/vimage_buffer/preferredalignmentandrowbytes(width:height:bitsperpixel:).md)
