# Casting a ReinterpretArray to Array without significant allocations

**URL:** <https://discourse.julialang.org/t/casting-a-reinterpretarray-to-array-without-significant-allocations/7808>\
**Category:** General Usage\
**Created:** [December 16, 2017, 11:57pm UTC](https://discourse.julialang.org/t/casting-a-reinterpretarray-to-array-without-significant-allocations/7808 "2017-12-16T23:57:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [December 16, 2017, 11:57pm UTC](https://discourse.julialang.org/t/casting-a-reinterpretarray-to-array-without-significant-allocations/7808/1 "2017-12-16T23:57:41Z")

</div>

I noticed in v0.7 that if I want a `Vector` out of a `reinterpret` operation rather than a `ReinterpretArray` that using the `Vector` constructor to do the conversion comes with a significant allocation cost proportional to the size of the array, seems like data is being copied. Is there a straightforward way to get a `Vector` essentially pointing to the same data instead of copying?

Similar post: [Big overhead with the new lazy reshape/reinterpret](https://discourse.julialang.org/t/big-overhead-with-the-new-lazy-reshape-reinterpret/7635)

MWE:

```julia
a = ones(Int, 10);
b = reinterpret(NTuple{2,Int}, a);
c = Array(reinterpret(NTuple{2,Int}, a));

a[1:2]
#=
2-element Array{Int64,1}:
 1
 1
=#

b[1]
#(1, 1)

c[1]
#(1, 1)

a[1] = 2;

b[1]
#(2, 1)

c[1]
#(1, 1)

```

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [December 17, 2017, 12:14am UTC](https://discourse.julialang.org/t/casting-a-reinterpretarray-to-array-without-significant-allocations/7808/2 "2017-12-17T00:14:52Z")

</div>

From what I understand, at the moment your only option in v0.7 is to use the “hack” in the thread you quote. Otherwise you either copy or use the lazy wrapper. An issue has been opened to try to improve the performance of the latter.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [December 17, 2017, 12:17am UTC](https://discourse.julialang.org/t/casting-a-reinterpretarray-to-array-without-significant-allocations/7808/3 "2017-12-17T00:17:18Z")

</div>

I see, I hope this hack can somehow be formalized and embedded in the language in an `Array!` function or something. `reinterpret` is really convenient but this penalty will make me think twice before using it.
