Skip to main content
`Ctrl`+`K`

# VecReplaceArray

Allows one to replace the array in a vector with an array provided by the user. This is useful to avoid copying an array into a vector.

## Synopsis

    #include "petscvec.h"
    PetscErrorCode VecReplaceArray(Vec vec, const PetscScalar array[])

Logically Collective; No Fortran Support

## Input Parameters

- vec - the vector

- array - the array

## Notes

Adding `const` to `array` was an oversight, as subsequent operations on `vec` would likely modify the data in `array`. However, we have kept it to avoid breaking APIs.

This permanently replaces the array and frees the memory associated with the old array. Use `VecPlaceArray()` to temporarily replace the array.

The memory passed in MUST be obtained with `PetscMalloc()` and CANNOT be freed by the user. It will be freed when the vector is destroyed.

## See Also

Vectors and Parallel Data, `Vec`, `VecGetArray()`, `VecRestoreArray()`, `VecPlaceArray()`, `VecResetArray()`

## Level

developer

## Location

src/vec/vec/interface/rvector.c

## Implementations

VecReplaceArray_Seq() in src/vec/vec/impls/seq/dvec2.c
VecReplaceArray_SeqKokkos() in src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx
VecReplaceArray_SeqViennaCL() in src/vec/vec/impls/seq/seqviennacl/vecviennacl.cxx

Index of all Vec routines
Table of Contents for all manual pages
Index of all manual pages