---
title: "init(bytesNoCopy:length:freeWhenDone:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsdata/init(bytesnocopy:length:freewhendone:)"
---

# init(bytesNoCopy:length:freeWhenDone:)

Initializes a newly allocated data object by adding the given number of bytes from the given buffer.

## Declaration

```swift
init(bytesNoCopy bytes: UnsafeMutableRawPointer, length: Int, freeWhenDone b: Bool)
```

## Parameters

- `bytes`: A buffer containing data for the new object. If flag is doc://com.apple.documentation/documentation/Swift/true, bytes must point to a memory block allocated with malloc.
- `length`: The number of bytes to hold from bytes. This value must not exceed the length of bytes.
- `b`: If doc://com.apple.documentation/documentation/Swift/true, the returned object takes ownership of the bytes pointer and frees it on deallocation.

## See Also

### Creating Data

- [init(bytes:length:)](foundation/nsdata/init(bytes:length:).md)
- [init(bytesNoCopy:length:)](foundation/nsdata/init(bytesnocopy:length:).md)
- [init(bytesNoCopy:length:deallocator:)](foundation/nsdata/init(bytesnocopy:length:deallocator:).md)
- [init(data:)](foundation/nsdata/init(data:).md)
