<!--
{
  "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/moveInitializeMemory(as:fromContentsOf:)-3gs5r",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sw20moveInitializeMemory2as14fromContentsOfSryxGxm_ADtRi_zlF"
  },
  "title" : "moveInitializeMemory(as:fromContentsOf:)"
}
-->

# moveInitializeMemory(as:fromContentsOf:)

Moves every element of an initialized source buffer into the
uninitialized memory referenced by this buffer, leaving the source memory
uninitialized and this buffer’s memory initialized.

```
@discardableResult func moveInitializeMemory<T>(as type: T.Type, fromContentsOf source: UnsafeMutableBufferPointer<T>) -> UnsafeMutableBufferPointer<T> where T : ~Copyable
```

## Parameters

`type`

The type of element to which this buffer’s memory will be bound.

`source`

A buffer referencing the values to copy.
The memory region underlying `source` must be initialized.

## Return Value

A typed buffer referencing the initialized elements.
The returned buffer references memory starting at the same
base address as this buffer, and its count is equal to `source.count`.

## Discussion

When calling the `moveInitializeMemory(as:fromContentsOf:)` method,
the memory referenced by the buffer must be uninitialized, or initialized
to a trivial type. The buffer must reference enough memory to store
`source.count` elements, and its `baseAddress` must be properly aligned
for accessing `C.Element`. After the method returns,
the memory referenced by the returned buffer is initialized and the
memory region underlying `source` is uninitialized.

This method initializes the buffer with the contents of `source`
until `source` is exhausted.
After calling `initializeMemory(as:fromContentsOf:)`, the memory
referenced by the returned `UnsafeMutableBufferPointer` instance is bound
to the type `T` and is initialized. This method does not change
the binding state of the unused portion of the buffer, if any.

> Note: The memory regions referenced by `source` and this buffer
> may overlap.

---

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)