---
title: SetLength
framework: driverkit
role: symbol
role_heading: Instance Method
path: driverkit/iobuffermemorydescriptor/setlength
---

# SetLength

Changes the length of the memory buffer.

## Declaration

```occ
virtual kern_return_t SetLength(uint64_t length);
```

## Parameters

- `length`: The new length of the memory buffer. This value must be less than or equal to the buffer’s capacity.

## Return Value

Return Value kIOReturnSuccess on success, or another value if an error occurs. See Error Codes.

## Discussion

Discussion Use this method to truncate an existing memory buffer. For example, you might call this method when repurposing an existing buffer for a new data type. The maximum capacity of the buffer remains unchanged, but the effective length of the buffer changes to the value you specify.

## See Also

### Managing the Buffer Contents

- [GetAddressRange](driverkit/iobuffermemorydescriptor/getaddressrange.md)
- [IOAddressSegment](driverkit/ioaddresssegment.md)
