Re: [go-nuts] [generics] notes on adding generics to a package

2021-01-29 Thread Ian Lance Taylor
On Fri, Jan 29, 2021 at 1:09 PM Ben Burkert wrote: > > I wrote a blog post on my experience updating a package to use the > latest proposed generics feature with the go2go tool. My overall > impression is quite good as it was able to solve some existing > problems with the package. Thanks to Go te

[go-nuts] [generics] notes on adding generics to a package

2021-01-29 Thread Ben Burkert
Hi Gophers, I wrote a blog post on my experience updating a package to use the latest proposed generics feature with the go2go tool. My overall impression is quite good as it was able to solve some existing problems with the package. Thanks to Go team & gopher community for all your work making ge

[go-nuts] Re: Virtual time for testing

2021-01-29 Thread mspr...@us.ibm.com
Volker: injecting sleep is a nice idea, in the general vein that Jesper said of injecting time. However, as soon as we zoom out a step and need to test both that generator and the goroutine(s) consuming and acting upon that channel activity, we get back to the essence of the original question:

Re: [go-nuts] explictly call make new cause space in heap?

2021-01-29 Thread Ian Lance Taylor
On Fri, Jan 29, 2021 at 9:10 AM xie cui wrote: > > when i call make new explictly, does it mean the space must be in heap, in my > mind, it still has chance to alloc in stack in some situation? > my question is is it must be in heap, or in some case it can alloc in stack? The builtin function ne

[go-nuts] Golang assertion issues

2021-01-29 Thread nishant gupta
Hi Gophers, Being new to programming and to Golang i am running into issues while asserting my test case. Looking for help here from the pros - Here is my function i want to Unit test - func validateK8ResourcesLength(resource prm.Resource) error { name := resource.GetName() namespace := resource

[go-nuts] explictly call make new cause space in heap?

2021-01-29 Thread xie cui
when i call make new explictly, does it mean the space must be in heap, in my mind, it still has chance to alloc in stack in some situation? my question is is it must be in heap, or in some case it can alloc in stack? -- You received this message because you are subscribed to the Google Groups

[go-nuts] Re: Passing string to a c-struct member of type void*

2021-01-29 Thread Alex
params[0].data = unsafe.Pointer(cstr) Note no & cuz cstr is already a pointer and &cstr is a pointer to a pointer On Friday, 29 January 2021 at 9:20:41 am UTC+8 yue.ni...@gmail.com wrote: > Hi, > > I have the following struct in C > == > struct DataStruct > { > const ch

[go-nuts] Re: Virtual time for testing

2021-01-29 Thread Volker Dobler
One way to do this is have an internal implementation like func generatorImpl(sleep func(time.Duration)) <-chan int and func generator just calls that one with time.Sleep. Tests are done against generatorImpl where you know have detailed control of how much (typically none) time is actually slept.

Re: [go-nuts] Re: []byte and string convert?

2021-01-29 Thread Robert Engels
And if you use byte[] everywhere rather than string be prepared for lots of panics and hard to detect bugs. :) > On Jan 29, 2021, at 8:35 AM, Amnon wrote: > > Generally yes. > As strings are immutable, and []byte is not, > if you convert from string -> []byte, you need a new copy which can be

Re: [go-nuts] Virtual time for testing

2021-01-29 Thread Jesper Louis Andersen
On Thu, Jan 28, 2021 at 10:15 PM Christian Worm Mortensen wrote: > Suppose I want to unit test this function: > > func generator() <-chan int { > ret := make(chan int) > go func() { > for i := 0; i < 10; i++ { > ret <- i > time.Sleep(time.Second) > } > }() > return ret > } > > What is a good way

[go-nuts] Re: []byte and string convert?

2021-01-29 Thread Amnon
Generally yes. As strings are immutable, and []byte is not, if you convert from string -> []byte, you need a new copy which can be written without changing the original string (which may be referred to elsewhere). If you convert from []byte -> string, then you need a new copy so that any later

Re: [go-nuts] Re: []byte and string convert?

2021-01-29 Thread 'Axel Wagner' via golang-nuts
Hi, neither is *always* the case. One example of where no allocation is done is when converting a []byte into a string to use as a map-index, as long as a) it is done in one expression and b) the key doesn't have to be stored (i.e. the access is read-only): b := []byte{70,111,111} m := make(map[s

[go-nuts] Re: []byte and string convert?

2021-01-29 Thread xie cui
I mean convert using s := "abcefg" b := []byte(s) s2 := string(b) not convert using some unsafe.Pointer trick. On Friday, January 29, 2021 at 8:51:57 PM UTC+8 xie cui wrote: > does convert string to []byte, and convert []byte to string alway alloc > new space, and the new space is in heap? >

[go-nuts] []byte and string convert?

2021-01-29 Thread xie cui
does convert string to []byte, and convert []byte to string alway alloc new space, and the new space is in heap? if it is not, please show some demo codes? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop