---
title: UnsafeRawBufferPointer
framework: swift
role: symbol
role_heading: Structure
path: swift/unsaferawbufferpointer
---

# UnsafeRawBufferPointer

A  nonowning collection interface to the bytes in a region of memory.

## Declaration

```swift
@frozen struct UnsafeRawBufferPointer
```

## Overview

Overview You can use an UnsafeRawBufferPointer instance in low-level operations to eliminate uniqueness checks and release mode bounds checks. Bounds checks are always performed in debug mode. An UnsafeRawBufferPointer instance is a view of the raw bytes in a region of memory. Each byte in memory is viewed as a UInt8 value independent of the type of values held in that memory. Reading from memory through a raw buffer is an untyped operation. In addition to its collection interface, an UnsafeRawBufferPointer instance also supports the load(fromByteOffset:as:) and loadUnaligned(fromByteOffset:as:) methods provided by UnsafeRawPointer, including bounds checks in debug mode. To access the underlying memory through typed operations, the memory must be bound to a trivial type. note: A trivial type can be copied bit for bit with no indirection or reference-counting operations. Generally, native Swift types that do not contain strong or weak references or other forms of indirection are trivial, as are imported C structs and enums. Copying memory that contains values of nontrivial types can only be done safely with a typed pointer. Copying bytes directly from nontrivial, in-memory values does not produce valid copies and can only be done by calling a C API, such as memmove(). UnsafeRawBufferPointer Semantics An UnsafeRawBufferPointer instance is a view into memory and does not own the memory that it references. Copying a variable or constant of type UnsafeRawBufferPointer does not copy the underlying memory. However, initializing another collection with an UnsafeRawBufferPointer instance copies bytes out of the referenced memory and into the new collection. The following example uses someBytes, an UnsafeRawBufferPointer instance, to demonstrate the difference between assigning a buffer pointer and using a buffer pointer as the source for another collection’s elements. Here, the assignment to destBytes creates a new, nonowning buffer pointer covering the first n bytes of the memory that someBytes references—nothing is copied: var destBytes = someBytes[0..<n] Next, the bytes referenced by destBytes are copied into byteArray, a new [UInt8] array, and then the remainder of someBytes is appended to byteArray: var byteArray: [UInt8] = Array(destBytes) byteArray += someBytes[n..<someBytes.count]

## Topics

### Initializers

- [init(_:)](swift/unsaferawbufferpointer/init(_:)-24m35.md)
- [init(_:)](swift/unsaferawbufferpointer/init(_:)-5ko6n.md)
- [init(_:)](swift/unsaferawbufferpointer/init(_:)-9uv4.md)
- [init(_:)](swift/unsaferawbufferpointer/init(_:)-rrzw.md)
- [init(rebasing:)](swift/unsaferawbufferpointer/init(rebasing:)-9mh4j.md)
- [init(rebasing:)](swift/unsaferawbufferpointer/init(rebasing:)-9sxid.md)
- [init(start:count:)](swift/unsaferawbufferpointer/init(start:count:).md)

### Instance Properties

- [baseAddress](swift/unsaferawbufferpointer/baseaddress.md)
- [bytes](swift/unsaferawbufferpointer/bytes.md)

### Instance Methods

- [assumingMemoryBound(to:)](swift/unsaferawbufferpointer/assumingmemorybound(to:).md)
- [bindMemory(to:)](swift/unsaferawbufferpointer/bindmemory(to:).md)
- [deallocate()](swift/unsaferawbufferpointer/deallocate().md)
- [isTriviallyIdentical(to:)](swift/unsaferawbufferpointer/istriviallyidentical(to:).md)
- [load(fromByteOffset:as:)](swift/unsaferawbufferpointer/load(frombyteoffset:as:).md)
- [loadUnaligned(fromByteOffset:as:)](swift/unsaferawbufferpointer/loadunaligned(frombyteoffset:as:)-2r9sy.md)
- [loadUnaligned(fromByteOffset:as:)](swift/unsaferawbufferpointer/loadunaligned(frombyteoffset:as:)-95fln.md)
- [withBytes(_:)](swift/unsaferawbufferpointer/withbytes(_:).md)
- [withMemoryRebound(to:_:)](swift/unsaferawbufferpointer/withmemoryrebound(to:_:).md)

### Default Implementations

- [AtomicRepresentable Implementations](swift/unsaferawbufferpointer/atomicrepresentable-implementations.md)
- [BidirectionalCollection Implementations](swift/unsaferawbufferpointer/bidirectionalcollection-implementations.md)
- [Collection Implementations](swift/unsaferawbufferpointer/collection-implementations.md)
- [CustomDebugStringConvertible Implementations](swift/unsaferawbufferpointer/customdebugstringconvertible-implementations.md)
- [RandomAccessCollection Implementations](swift/unsaferawbufferpointer/randomaccesscollection-implementations.md)
- [Sequence Implementations](swift/unsaferawbufferpointer/sequence-implementations.md)

## Relationships

### Conforms To

- [AtomicRepresentable](synchronization/atomicrepresentable.md)
- [BidirectionalCollection](swift/bidirectionalcollection.md)
- [BitwiseCopyable](swift/bitwisecopyable.md)
- [Collection](swift/collection.md)
- [ContiguousBytes](foundation/contiguousbytes.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [DataProtocol](foundation/dataprotocol.md)
- [Escapable](swift/escapable.md)
- [RandomAccessCollection](swift/randomaccesscollection.md)
- [Sequence](swift/sequence.md)

## See Also

### Raw Pointers

- [UnsafeRawPointer](swift/unsaferawpointer.md)
- [UnsafeMutableRawPointer](swift/unsafemutablerawpointer.md)
- [UnsafeMutableRawBufferPointer](swift/unsafemutablerawbufferpointer.md)
