---
title: withData
framework: Kernel
role: symbol
role_heading: Type Method
platforms: [driverkit 19.0+, macOS 10.15.2+]
path: kernel/osdata/3433845-withdata
---

# withData

Allocates an OSData object with a copy of bytes from a subset of another OSData.

## Declaration

```occ
static OSDataPtr withData(const OSData *inData, size_t start, size_t numBytes);
```

```occ
static OSPtr<OSData> withData(const OSData *inData, unsigned int start, unsigned int numBytes);
```

## Parameters

- `inData`: An OSData object to copy. The data will be copied at the time of the call.
- `start`: An offset into the OSData object to copy from.
- `numBytes`: The length of data to copy. If (start + numBytes) exceeds the length of inData, the call will fail.

## Return Value

Return Value NULL on failure, otherwise the allocated OSData with reference count 1 to be released by the caller.

## See Also

### Creating a Data Object

- [withBytes](driverkit/osdata/withbytes.md)
- [withBytesNoCopy](driverkit/osdata/withbytesnocopy.md)
- [withCapacity](kernel/osdata/3180885-withcapacity.md)
- [withData](kernel/osdata/3180886-withdata.md)
- [OSDataPtr](driverkit/osdataptr.md)
- [free](kernel/osdata/3180878-free.md)
