It seems easier to work with native types when writing to a file (that is later MMapped) compared to writing structs. Since my struct has two
Int32 I thought of merging them to an
Int64 (by bitshifting), writing them to a file, and then Mmap them using reinterpret. Like so:
function pack(numb1::Int32, numb2::Int32) # Low bits = numb1 # High bits = numb2 return Int64(numb1) << 32 | numb2 end struct S numb2::Int32 numb1::Int32 end packed = pack(Int32(100), Int32(10)) println(packed) # --> 429496729610 s = reinterpret(S, [packed]) # --> S(100, 10)
I wonder two things:
It seems that the high bits are interpreted first and then the low bits - is this correct?
numb1in the low bits and when passed to
Susing reinterpret it is read second (not first) hence I have
numb2first in my struct.
Is this an okay practice for this situation or am I missing something that can go wrong here?