sure you can. no memory space difference. On Wednesday, July 12, 2017 at 7:44:47 PM UTC+8, Matthew Zimmerman wrote: > > Why not use struct{}? Is what is recommended for maps to notate a set > (only the keys mean something). > > https://play.golang.org/p/fxtEWejqdh > > On Tue, Jul 11, 2017, 11:34 PM Rader <rade...@gmail.com <javascript:>> > wrote: > >> I found the position of `[0]byte` in the struct matters. >> type bar2 struct { >> A int >> _ [0]byte >> } >> >> differs from >> >> type bar3 struct { >> _ [0]byte >> A int >> } >> >> >> >> see the full example <https://play.golang.org/p/wJkDPQ0PQ3> >> >> >> >> On Wednesday, July 12, 2017 at 10:44:04 AM UTC+8, Rader wrote: >>> >>> they both have the same size, eg. following structs bar and bar2 both >>> take 16 bytes memory on a x64 machine. >>> >>> package main >>> >>> import ( >>> "fmt" >>> "unsafe" >>> ) >>> >>> type bar struct { >>> A int >>> _ bool >>> } >>> >>> type bar2 struct { >>> A int >>> _ [0]byte >>> >>> } >>> >>> func main() { >>> bar := bar{} >>> bar2 := bar2{} >>> fmt.Printf("size of bar:%v\n", unsafe.Sizeof(bar)) >>> fmt.Printf("size of bar2:%v\n", unsafe.Sizeof(bar2)) >>> } >>> >>> >>> >>> On Thursday, July 6, 2017 at 11:45:30 AM UTC+8, kortschak wrote: >>>> >>>> On Wed, 2017-07-05 at 17:26 -0700, rsr via golang-nuts wrote: >>>> > type bar struct { >>>> > A int >>>> > _ bool >>>> > } >>>> >>>> >>>> or `type bar struct { A int; _ [0]byte }` to avoid the additional byte >>>> use. >>>> >>>> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> >
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.