<!--
{
  "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/UnsafeMutableRawPointer/copyMemory(from:byteCount:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sv10copyMemory4from9byteCountySV_SitF"
  },
  "title" : "copyMemory(from:byteCount:)"
}
-->

# copyMemory(from:byteCount:)

Copies the specified number of bytes from the given raw pointer’s memory
into this pointer’s memory.

```
func copyMemory(from source: UnsafeRawPointer, byteCount: Int)
```

## Parameters

`source`

A pointer to the memory to copy bytes from. The memory in the
region `source..<(source + byteCount)` must be initialized to a
trivial type.

`byteCount`

The number of bytes to copy. `byteCount` must not be
negative.

## Discussion

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

The memory in the region `source..<(source + byteCount)` may overlap with
the memory referenced by this pointer.

After calling `copyMemory(from:byteCount:)`, the `byteCount` bytes of
memory referenced by this pointer 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)