# Concatenating vectors into a single vector without allocating memory (opposite of @view)

**URL:** <https://discourse.julialang.org/t/concatenating-vectors-into-a-single-vector-without-allocating-memory-opposite-of-view/6339>\
**Category:** General Usage\
**Created:** [October 9, 2017, 2:08am UTC](https://discourse.julialang.org/t/concatenating-vectors-into-a-single-vector-without-allocating-memory-opposite-of-view/6339 "2017-10-09T02:08:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [October 9, 2017, 2:08am UTC](https://discourse.julialang.org/t/concatenating-vectors-into-a-single-vector-without-allocating-memory-opposite-of-view/6339/1 "2017-10-09T02:08:48Z")

</div>

Suppose we want to construct one large vector `x` and three smaller vectors `x1`, `x2`, `x3` such that a relationship `x = [x1; x2; x3]` is always maintained. Provided that each of the smaller vectors has 100 entries, this can be achieved by

```julia
julia> x = rand(300);

julia> x1 = @view(x[1:100]); x2 = @view(x[101:200]); x3 = @view(x[201:300]);

```

Here, real memory is allocated to `x`, and `x1`, `x2`, `x3` are just the views the portions of this memory.

What I would like achieve is something opposite: I would like to create three independent vectors `x1`, `x2`, `x3` first and construct `x` such that its each third views one of the memory allocated to `x1`, `x2`, `x3`. In other words, I would like to do something like

```julia
julia> x1 = rand(100); x2 = rand(100); x3 = rand(100);

julia> x = [@view(x1); @view(x2); @view(x3)];

```

though this code does not work.

Does this capability already exist in Julia, or are there any packages doing this?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 9, 2017, 2:12am UTC](https://discourse.julialang.org/t/concatenating-vectors-into-a-single-vector-without-allocating-memory-opposite-of-view/6339/2 "2017-10-09T02:12:01Z")

</div>

> [@wsshin](#):
>
> Does this capability already exist in Julia, or are there any packages doing this?

CatViews.jl

> **[GitHub - ahwillia/CatViews.jl: Concatenated Array views in Julia.](https://github.com/ahwillia/CatViews.jl)**
>
> Concatenated Array views in Julia. Contribute to ahwillia/CatViews.jl development by creating an account on GitHub.

Might need an update for v0.6.
