# 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[])
```
Not Collective


## Input Parameters

- ***vec -*** the vector
- ***array -*** the array



## Notes
This permanently replaces the array and frees the memory associated
with the old 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.

Not supported from Fortran




## See Also
 `VecGetArray()`, `VecRestoreArray()`, `VecPlaceArray()`, `VecResetArray()`


## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/interface/rvector.c.html#VecReplaceArray">src/vec/vec/interface/rvector.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/dvec2.c.html#VecReplaceArray_Seq">VecReplaceArray_Seq in src/vec/vec/impls/seq/dvec2.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx.html#VecReplaceArray_SeqKokkos">VecReplaceArray_SeqKokkos in src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/seqcuda/veccuda.c.html#VecReplaceArray_SeqCUDA">VecReplaceArray_SeqCUDA in src/vec/vec/impls/seq/seqcuda/veccuda.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/seqhip/vechip.hip.c.html#VecReplaceArray_SeqHIP">VecReplaceArray_SeqHIP in src/vec/vec/impls/seq/seqhip/vechip.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/seqviennacl/vecviennacl.cxx.html#VecReplaceArray_SeqViennaCL">VecReplaceArray_SeqViennaCL in src/vec/vec/impls/seq/seqviennacl/vecviennacl.cxx</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/vec/vec/interface/rvector.c)


[Index of all Vec routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
