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

# init(bytesNoCopy:length:)

Initializes a data object filled with a given number of bytes of data from a given buffer.

## Declaration

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

## Parameters

- `bytes`: A buffer containing data for the new object. 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.

## Return Value

Return Value A data object initialized by adding to it length bytes of data from the buffer bytes. The returned object might be different than the original receiver.

## Discussion

Discussion The returned object takes ownership of the bytes pointer and frees it on deallocation. Therefore, bytes must point to a memory block allocated with malloc.

## See Also

### Creating Data

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