---
title: withBytes
framework: driverkit
role: symbol
role_heading: Static Method
path: driverkit/osdata/withbytes
---

# withBytes

Allocates an OSData object with a copy of bytes.

## Declaration

```occ
static OSDataPtr withBytes(const void *bytes, size_t numBytes);
```

## Parameters

- `bytes`: C-pointer to untyped data. The data will be copied at the time of the call.
- `numBytes`: Count of bytes to be copied.

## 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

- [withBytesNoCopy](driverkit/osdata/withbytesnocopy.md)
- [withCapacity](driverkit/osdata/withcapacity.md)
- [withData](driverkit/osdata/withdata-9y3g.md)
- [withData](driverkit/osdata/withdata-4rd8n.md)
- [OSDataCreate](driverkit/osdatacreate.md)
- [OSDataPtr](driverkit/osdataptr.md)
- [free](driverkit/osdata/free.md)
