Re: [go-nuts] Why is ioutil.Discard implemented using an int and not an empty struct?

2016-10-17 Thread adonovan via golang-nuts
On Monday, 17 October 2016 09:15:33 UTC-4, Axel Wagner wrote: > > However, the compiler might be clever enough to optimize that out with > inlining and escape analysis. And indeed, I'm failing to trigger the > behavior with any simple testcase. So I might be wrong here. Would be > interested in

Re: [go-nuts] Why is ioutil.Discard implemented using an int and not an empty struct?

2016-10-17 Thread 'Axel Wagner' via golang-nuts
There is no semantic difference. Disclaimer: On everything that follows, I'm not an expert (and it seems I'm wrong. Not sure exactly how, though). Though there *might* be a (*very*) slight advantage to using a struct{}. All struct{}'s have the same address in gc, so if you put a struct{} into an

[go-nuts] Why is ioutil.Discard implemented using an int and not an empty struct?

2016-10-17 Thread Rodolfo Carvalho
Hi, I noticed that when io.Discard was introduced in https://codereview.appspot.com/4426066/, it replaced code like: type devNull struct{} With: type devNull int Both had the very same implementation of the Write method: func (devNull) Write(p []byte) (int, os.Error) { return len(