The following seems to work for me
using StaticArrays
struct Dummy
B::SVector{34,UInt8}
end
@assert sizeof(Dummy) == sum(sizeof.(fieldtypes(Dummy)))
struct Dummy32
A::Float32
B::SVector{32,UInt8}
end
@assert sizeof(Dummy32) == sum(sizeof.(fieldtypes(Dummy32)))
struct Dummy34
A::Float32
B::SVector{34,UInt8}
end
dummy1 = Dummy34(0.0, SVector((0 for _ in 1:34)...))
open("test.dat", "w") do fp
write(fp, Ref(dummy1))
@show position(fp) # --> 40
end
open("test.dat", "r") do fp
dummy2 = Ref{Dummy34}()
read!(fp, dummy2)
@show position(fp) # --> 40
@assert dummy2[] == dummy1
end
Regarding the size of Dummy34: I could imagine some kind of 32 bit alignment.