# ANN: UnsafeArray.jl

**URL:** <https://discourse.julialang.org/t/ann-unsafearray-jl/10452>\
**Category:** General Usage\
**Created:** [April 20, 2018, 11:44am UTC](https://discourse.julialang.org/t/ann-unsafearray-jl/10452 "2018-04-20T11:44:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Post date:** [April 20, 2018, 11:44am UTC](https://discourse.julialang.org/t/ann-unsafearray-jl/10452/1 "2018-04-20T11:44:18Z")

</div>

Dear all,

I’d like to present [UnsafeArray.jl](https://github.com/oschulz/UnsafeArrays.jl). It’s main function is to provide (heap-)allocation-free array views. It provides a (hopefully) safe alternative to `ArrayViews.UnsafeArrayView`, and integrates with `Base.view()` and `Base.SubArray`.

Example:

```julia
@uviews A B C ... begin
    # Within this scope, arrays A B C ... are replaced by stack-allocated (pointer-based)
    # bitstype UnsafeArrays, view()'s on these are also bitstypes and stack-allocated.
    # The original arrays are protected from GC, but it's the user's responsibility not to
    # let the unsafe version of A B C ... escape from this scope.
end

```

I did [some initial benchmarking](https://github.com/oschulz/UnsafeArrays.jl/issues/1), the results are quite encouraging.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [April 20, 2018, 4:04pm UTC](https://discourse.julialang.org/t/ann-unsafearray-jl/10452/2 "2018-04-20T16:04:37Z")

</div>

Could you compare your design goals with the design goals of [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl)?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [April 20, 2018, 8:06pm UTC](https://discourse.julialang.org/t/ann-unsafearray-jl/10452/3 "2018-04-20T20:06:41Z")

</div>

StaticArrays are statically sized, allowing very heavy specialisations and optimizations for a specific shape. Since some subtypes are also immutable, the _whole_ array can be stack allocated.

The above Package offers stack allocated _views_ into normal heap allocated julia arrays 😉 So the array itself is not immutable and doesn’t hold its size as a static type parameter.

---

<div class="post-metadata">

**Author:** ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Post date:** [April 20, 2018, 8:10pm UTC](https://discourse.julialang.org/t/ann-unsafearray-jl/10452/4 "2018-04-20T20:10:34Z")

</div>

> [@juliohm](#):
>
> Could you compare your design goals with the design goals of StaticArrays.jl ?

StaticArrays (please correct me if I’m wrong) is something very different, it provides stack-allocated arrays of fixed/hard-coded size. UnsafeArrays provides stack-allocated views (of arbitrary size) of heap-allocated arrays.

---

<div class="post-metadata">

**Author:** ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Post date:** [April 20, 2018, 8:11pm UTC](https://discourse.julialang.org/t/ann-unsafearray-jl/10452/5 "2018-04-20T20:11:12Z")

</div>

Darn, you were faster, Simon. 😉
