go - Should I trust the size reported by "aligncheck" -


i have struct defined below:

type mystruct struct {     [10]byte     b uint64     c uint16 } 

and use binary.read below

err = binary.read(r, binary.bigendian, &mystruct)  // mystruct mystruct type 

i got correct value fields in mystruct. , following code read reader r correct result.

but aligncheck side mystruct have size 24 32. binary byte read, should take 20 bytes.

so not sure got luck correct result or part of go tool chain pack struct proper size?

as tim cooper stated in comment, you're comparing 2 different representations of same data. aligncheck tells how space occupied in memory (heap/stack) instance of struct, affected struct field alignment , padding, reasons explained @ length elsewhere.

binary.read , .write, on other hand, not trying store objects in memory boundary alignment; they're writing stream of contiguous bytes. therefor these output same size struct regardless of order of fields, , minimum size of struct (because there no padding added).


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -