# Why does \`reinterpret\` cause an extra allocation?

**URL:** https://discourse.julialang.org/t/why-does-reinterpret-cause-an-extra-allocation/8833
**Category:** General Usage
**Created:** [February 5, 2018, 3:33pm UTC](https://discourse.julialang.org/t/why-does-reinterpret-cause-an-extra-allocation/8833 "2018-02-05T15:33:01Z")
**Posts on this page:** 1
**Showing post:** 24

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [February 6, 2018, 12:24pm UTC](https://discourse.julialang.org/t/why-does-reinterpret-cause-an-extra-allocation/8833/24 "2018-02-06T12:24:39Z")

</div>

Does not fix the speed on my machine ☹

I’ll rebuild and try more systematically again later.  
[edit: still not fixed for me.]

PS about the padding: Now I believe its mostly leftover register contents, not stack memory; but whatever happens probably depends a lot on how the compiler feels today. Well, the filling of the padding is UB, so whatever.

After pondering the source of reinterpret-array:

```julia
struct bax2
       a::Int8
       b::Int
       c::Int8
end

 A4=[bax2(-1,-1,-1)];
A4r=reinterpret(UInt8, A4);
@show A4r[2];
# A4r[2] = 0xfd
A4r[2]=2;
@show A4r[2];
#A4r[2] = 0xfd

```

I guess I’ll open an issue for that one, even though the fact that reinterpret goes via abstract array kinda implies this problem (it would be valid, I think, to have a “structure-packed array” where the padding bytes simply don’t exist and hence cannot be reinterpreted-- ie `sizeof` is not informative for abstract arrays that don’t guarantee a contiguous memory layout).

edit: Issue opened, [https://github.com/JuliaLang/julia/issues/25908](https://github.com/JuliaLang/julia/issues/25908)

---

_[View the full topic](https://discourse.julialang.org/t/why-does-reinterpret-cause-an-extra-allocation/8833)._
