-j
var string t = s
What is a pointer wrapper value?
in all seriousness, if you review the git history of the Go spec you'll find the word "reference" was purged about two years ago, in effect, to try to stem these discussions.
I like Alan's "useful definition" of a semantically reference type, which involves shared mutable state.
About the string type, I also like the implementation detail that
var string t = s
is O(1) in memory and running time, i.e. it happens internally to "copy the reference, not the bytes" : see https://play.golang.org/p/p-PD_yOnw6
It usually doesn't make much of a difference because most strings are short, and also they are not the best data structure to manipulate data (unlike []byte). But I take this implementation detail into account when I want to optimize code, especially to reduce the need for memory allocation.
On Thursday, October 20, 2016 at 7:31:25 PM UTC+8, Val wrote:I like Alan's "useful definition" of a semantically reference type, which involves shared mutable state.
About the string type, I also like the implementation detail that
var string t = s
is O(1) in memory and running time, i.e. it happens internally to "copy the reference, not the bytes" : see https://play.golang.org/p/p-PD_yOnw6
It usually doesn't make much of a difference because most strings are short, and also they are not the best data structure to manipulate data (unlike []byte). But I take this implementation detail into account when I want to optimize code, especially to reduce the need for memory allocation.
So, comparing two long same stings at the first time may spend much time?
On Thursday, October 20, 2016 at 9:58:46 PM UTC+8, T L wrote:
On Thursday, October 20, 2016 at 7:31:25 PM UTC+8, Val wrote:I like Alan's "useful definition" of a semantically reference type, which involves shared mutable state.
About the string type, I also like the implementation detail that
var string t = s
is O(1) in memory and running time, i.e. it happens internally to "copy the reference, not the bytes" : see https://play.golang.org/p/p-PD_yOnw6
It usually doesn't make much of a difference because most strings are short, and also they are not the best data structure to manipulate data (unlike []byte). But I take this implementation detail into account when I want to optimize code, especially to reduce the need for memory allocation.
So, comparing two long same stings at the first time may spend much time?
It looks golang 1.7.1 doesn't release one copy of underlying data after comparings:
https://play.golang.org/p/Lu9FZ9iqn6
https://play.golang.org/p/-wE2oUGce1
--
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.
For more options, visit https://groups.google.com/d/optout.
Ian
The confusion I have had is rather with nilability.A channel can be nil even though it is not explicitly a pointer.
type T struct {i intp *int}
--
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+unsubscribe@googlegroups.com.
I think you should clarify that this is because T only contains pointers. If T were:type T struct {i intp *int}
then it would suddenly become non-reference type, as defined in this thread, as a change to i will not be noticed by other copies of a given T.-Paul
On Fri, Oct 21, 2016 at 8:20 AM, 'Alan Donovan' via golang-nuts <golan...@googlegroups.com> wrote:
On 21 October 2016 at 11:15, T L <tapi...@gmail.com> wrote:On Friday, October 21, 2016 at 10:01:43 PM UTC+8, Ian Lance Taylor wrote:On Fri, Oct 21, 2016 at 6:52 AM, Henrik Johansson <dahan...@gmail.com> wrote:
> The confusion I have had is rather with nilability.
> A channel can be nil even though it is not explicitly a pointer.
It's a basic design decision in Go that every type has a zero value.
For the "reference types" (pointer, channel, map, slice, interface)
that zero value is named "nil".
I have a question, should the following type be called reference type?type T struct {p *int}By the definition I gave, yes, because an instance of T contains a reference to an int variable. All copies of a given T value share the same int variable, and a change to that variable by any one will be observed by all the others.
--
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.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.