<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UnsafeMutableRawBufferPointer/copyMemory(from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sw10copyMemory4fromySW_tF"
  },
  "title" : "copyMemory(from:)"
}
-->

# copyMemory(from:)

Copies the bytes from the given buffer to this buffer’s memory.

```
func copyMemory(from source: UnsafeRawBufferPointer)
```

## Parameters

`source`

A buffer of raw bytes. `source.count` must
be less than or equal to this buffer’s `count`.

## Discussion

If the `source.count` bytes of memory referenced by this buffer are bound
to a type `T`, then `T` must be a trivial type, the underlying pointer
must be properly aligned for accessing `T`, and `source.count` must be a
multiple of `MemoryLayout<T>.stride`.

The memory referenced by `source` may overlap with the memory referenced
by this buffer.

After calling `copyMemory(from:)`, the first `source.count` bytes of
memory referenced by this buffer are initialized to raw bytes. If the
memory is bound to type `T`, then it contains values of type `T`.

---

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)