# Disable memory alignment inside struct

**URL:** https://discourse.julialang.org/t/disable-memory-alignment-inside-struct/132942
**Category:** General Usage
**Tags:** fortran, io
**Created:** [October 7, 2025, 9:59am UTC](https://discourse.julialang.org/t/disable-memory-alignment-inside-struct/132942 "2025-10-07T09:59:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Yotam\_Ohad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yotam_ohad/32/218880_2.png) [@Yotam\_Ohad](https://discourse.julialang.org/u/Yotam_Ohad)
#### Post date: [October 7, 2025, 9:59am UTC](https://discourse.julialang.org/t/disable-memory-alignment-inside-struct/132942/1 "2025-10-07T09:59:53Z")

</div>

I have a (somewhat old) file that was created from a Fortran script and contains a struct without any padding. I try to read the file as follows

```julia-auto
struct Foo
    id::UInt32
    Value::Int64
end
io = open(filepath, "r")
rows = Mmap.mmap(io, Vector{Foo}, nrows)
sa = StructArray(rows)

```

However, because the default behavior is to add padding between `id` and `Value` the size of `Foo` is wrong and I get nonsense.

Is there a way to disable the padding?

My main concern here is to optimize loading the file into a StructArray, as the files are ~10GB and I need to load hundreds of them in my computations while also query the entire files. If there is a better way to load them I’d be happy to learn.

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [October 7, 2025, 10:24am UTC](https://discourse.julialang.org/t/disable-memory-alignment-inside-struct/132942/2 "2025-10-07T10:24:37Z")

</div>

Maybe FortranFiles.jl is what you need?

But unless you are reading these only once, maybe it is worthwhile to convert them to Arrow or other modern format.

---

<div class="post-metadata">

### Author: ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)
#### Post date: [October 8, 2025, 3:37pm UTC](https://discourse.julialang.org/t/disable-memory-alignment-inside-struct/132942/3 "2025-10-08T15:37:24Z")

</div>

> [@Yotam\_Ohad](#):
>
> Is there a way to disable the padding?

I’m not sure about padding in vectors, but could you do:

```julia-auto
const T = NTuple{12, UInt8}
rows = Mmap.mmap(io, Vector{T}, nrows)

```

then you can reinterpret the `UInt8` tuples:

```julia-auto
a = rows[147]
reinterpret(UInt32, a[1:4])
reinterpret(Int64, a[5:end])

```

That is, something like this:

```julia-auto
using Mmap
using StructArrays

const T = NTuple{12, UInt8}

function getdata(filename)
    open(filename, "r") do io
        rows = Mmap.mmap(io, Vector{T}, 1_000_000_000)
        a = map(x -> reinterpret(UInt32, x[1:4]), rows)
        b = map(x -> reinterpret(Int64, x[5:12]), rows)
        StructArray(a=a, b=b)
    end
end

sa = getdata("/tmp/fort1.dat")

```
