<!--
{
  "availability" : [
    "DriverKit: -",
    "iOS: -",
    "iPadOS: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "DriverKit",
  "identifier" : "/documentation/DriverKit/OSData",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "DriverKit"
    ],
    "preciseIdentifier" : "c:@S@OSData"
  },
  "title" : "OSData"
}
-->

# OSData

A container for untyped data.

```
class OSData;
```

## Overview

OSData represents an array of bytes as a container object. OSData objects are mutable: You can add bytes to them and overwrite portions of the byte array.

OSData provides no concurrency protection; it’s up to the usage context to provide any protection necessary.

## Topics

### Creating a Data Object

[`static OSDataPtr withBytes(const void *bytes, size_t numBytes);`](/documentation/DriverKit/OSData/withBytes)

Allocates an OSData object with a copy of bytes.

[`static OSDataPtr withBytesNoCopy(void *bytes, size_t numBytes);`](/documentation/DriverKit/OSData/withBytesNoCopy)

Allocates an OSData object with a copy of bytes.

[`static OSDataPtr withCapacity(uint32_t capacity);`](/documentation/DriverKit/OSData/withCapacity)

Allocates an OSData object with preallocated capacity.

[`static OSDataPtr withData(const OSData *inData);`](/documentation/DriverKit/OSData/withData-9y3g)

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

[`static OSDataPtr withData(const OSData *inData, size_t start, size_t numBytes);`](/documentation/DriverKit/OSData/withData-4rd8n)

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

[`OSDataPtrOSDataCreate(const void *bytes, size_t length);`](/documentation/DriverKit/OSDataCreate)

[`typedef OSData * OSDataPtr;`](/documentation/DriverKit/OSDataPtr)

[`virtual void free();`](/documentation/DriverKit/OSData/free)

### Getting Bytes

[`const void * getBytesNoCopy() const;`](/documentation/DriverKit/OSData/getBytesNoCopy-91vcg)

Returns a pointer to the OSData object’s internal data buffer.

[`const void * getBytesNoCopy(size_t start, size_t numBytes) const;`](/documentation/DriverKit/OSData/getBytesNoCopy-53puz)

Returns a pointer to the OSData object’s internal data buffer.

[`size_t OSDataGetBytes(OSDataPtr obj, void *buffer, size_t offset, size_t length);`](/documentation/DriverKit/OSDataGetBytes)

[`const void *OSDataGetBytesPtr(OSDataPtr obj, size_t offset, size_t length);`](/documentation/DriverKit/OSDataGetBytesPtr)

### Appending Data to the Object

[`bool appendBytes(const void *bytes, size_t numBytes);`](/documentation/DriverKit/OSData/appendBytes-lbqa)

Appends a buffer of bytes to the OSData object’s internal data buffer.

[`bool appendBytes(const OSData *aDataObj);`](/documentation/DriverKit/OSData/appendBytes-38hs5)

Appends a buffer of bytes to the OSData object’s internal data buffer.

[`bool appendBytes(const void *bytes, size_t numBytes);`](/documentation/DriverKit/OSData/appendBytes-lbqa)

Appends a buffer of bytes to the OSData object’s internal data buffer.

[`bool OSDataAppendBytes(OSDataPtr data, const void *bytes, size_t length);`](/documentation/DriverKit/OSDataAppendBytes)

### Inspecting a Data Object

[`size_t getCapacity() const;`](/documentation/DriverKit/OSData/getCapacity)

Returns length of preallocated capacity.

[`size_t getLength() const;`](/documentation/DriverKit/OSData/getLength)

Returns length of data present.

[`size_t OSDataGetLength(OSDataPtr obj);`](/documentation/DriverKit/OSDataGetLength)

### Comparing Data Objects

[`bool isEqualTo(const OSData *aDataObj) const;`](/documentation/DriverKit/OSData/isEqualTo-2kdml)

Compares the data with an OSData

[`virtual bool isEqualTo(const OSMetaClassBase *anObject) const;`](/documentation/DriverKit/OSData/isEqualTo-4xz0j)

Compares the data with an OSObject

[`bool isEqualTo(const OSString *aString) const;`](/documentation/DriverKit/OSData/isEqualTo-5ssf5)

Compares the data with an OSString

[`bool isEqualTo(const void *bytes, size_t numBytes) const;`](/documentation/DriverKit/OSData/isEqualTo-79gqy)

Compares the data with a pointer to bytes

## Relationships

### Inherits From

[`OSContainer`](/documentation/DriverKit/OSContainer)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)