[go-nuts] Re: concurrent write-only to map ok?

2017-10-13 Thread Alex Buchanan
So many good answers! Lots of different ways to accomplish this. I'll say that in this specific case, which is does not require every ounce of performance, syncmap is by far the simplest and least amount of code, so readability wins on this one. -- You received this message because you are sub

[go-nuts] Re: Newbie Implementation of Set Partitions Generator

2017-10-13 Thread john lynch
"I'm sure it'll reveal an error in my thinking" To avoid importing math I had changed my upper limit early on but I 'd misread it. The critical line in error should be changed to: for j := 0; j < int(math.Pow(2.0, float64(len(set)))/2.0); j++ { -- You received this message because you are

Re: [go-nuts] cgo multiple definition errors

2017-10-13 Thread Ian Lance Taylor
On Fri, Oct 13, 2017 at 4:24 PM, 'Pushkar' via golang-nuts wrote: > > I was getting the multiple definition error when I put my C files in the > same directory as my go files. > Only after reading some online posts I figured I should put my code into a > separate directory. > > The introductory pa

[go-nuts] cgo multiple definition errors

2017-10-13 Thread 'Pushkar' via golang-nuts
I was getting the multiple definition error when I put my C files in the same directory as my go files. Only after reading some online posts I figured I should put my code into a separate directory. The introductory page to cgo doesn't mention this. It would save newbies some time if did: https

[go-nuts] Re: concurrent write-only to map ok?

2017-10-13 Thread Slawomir Pryczek
I think using standard sync'ed map may be bad idea for this use case (write-only access), especially taking into account that it's optimized for read access and stable keys, so each write will acquire mutex anyway. if nothing is read from that map during the threads run, it should be probably m

Re: [go-nuts] Newbie Implementation of Set Partitions Generator

2017-10-13 Thread john lynch
Thanks Michael, I appreciate the information. Because I'm trying to learn Go, I'm more interested in what should cause it to stop running part way through the process without generating an error. It just seems bizarre to me but I'm sure it'll reveal an error in my thinking. -- You receive

[go-nuts] Re: Newbie Implementation of Set Partitions Generator

2017-10-13 Thread john lynch
Thanks Ian, You are correct (although the post I submitted yesterday had the clobbering lines incorrect - that was one of my experiments to see if rebuilding the 3D slice differently would overcome the problem). The code below is my original. Yes, the function works by building fresh version

[go-nuts] Re: Newbie Implementation of Set Partitions Generator

2017-10-13 Thread john lynch
The top 3 lines of the function I posted yesterday were not correct but I couldn't edit them. Unfortunately, in my experiments with the slice I had changed them and didn't realize before posting. The correct version is: package main import ( "fmt" "time") func get_partitions(set []s

Re: [go-nuts] Re: go on Windows 10 from the bash shell (and the cmd shell)

2017-10-13 Thread Gerald Henriksen
On Thu, 12 Oct 2017 22:08:44 -0700 (PDT), you wrote: > >On Thursday, October 12, 2017 at 8:31:52 PM UTC-4, Gerald wrote: >> >> The MSI is a Windows application, whereas apt-get would install the >> Linux binary of go. >> >> WSL has you actually running Linux binaries on Windows unless you >> sp

Re: [go-nuts] concurrent write-only to map ok?

2017-10-13 Thread Marvin Renich
* Alex Buchanan [171013 14:06]: > Basically, I want to spawn a goroutine per object, objects have unique IDs, > and I want each routine to write its results to a shared map. Nothing will > be reading from the map while the goroutines are running. You didn't give much detail, but if the map is m

Re: [go-nuts] Blocking in C functions called from go

2017-10-13 Thread Ian Lance Taylor
On Fri, Oct 13, 2017 at 12:23 PM, 'Pushkar' via golang-nuts wrote: > I need to call some C functions from Go. I think I know how to proceed using > cgo. > However, I was wondering how goroutines and blocking calls in the C > functions work together. > So in the below example (pseudocode) will the

[go-nuts] Blocking in C functions called from go

2017-10-13 Thread 'Pushkar' via golang-nuts
I need to call some C functions from Go. I think I know how to proceed using cgo. However, I was wondering how goroutines and blocking calls in the C functions work together. So in the below example (pseudocode) will the goroutine be suspended when the pthread_lock call is waiting to acquire the

Re: [go-nuts] concurrent write-only to map ok?

2017-10-13 Thread Michael Jones
You can also write to a channel and have the reader of the channel write to the map On Fri, Oct 13, 2017 at 11:36 AM, Shawn Milochik wrote: > On Fri, Oct 13, 2017 at 2:33 PM, Alex Buchanan > wrote: > >> Thanks for the quick help guys! >> >> I ended up using https://godoc.org/golang.org/x/sync/s

Re: [go-nuts] concurrent write-only to map ok?

2017-10-13 Thread Shawn Milochik
On Fri, Oct 13, 2017 at 2:33 PM, Alex Buchanan wrote: > Thanks for the quick help guys! > > I ended up using https://godoc.org/golang.org/x/sync/syncmap > > Cool, that's what it's there for. Personally I'd avoid using empty interfaces, though. -- You received this message because you are subscr

Re: [go-nuts] concurrent write-only to map ok?

2017-10-13 Thread Alex Buchanan
Thanks for the quick help guys! I ended up using https://godoc.org/golang.org/x/sync/syncmap On Friday, October 13, 2017 at 11:22:44 AM UTC-7, Shawn Milochik wrote: > > On Fri, Oct 13, 2017 at 2:05 PM, Alex Buchanan > wrote: > >> Basically, I want to spawn a goroutine per object, objects have un

[go-nuts] Re: go on Windows 10 from the bash shell (and the cmd shell)

2017-10-13 Thread Sotirios Mantziaris
follow the procedure of installing go in linux. set the following in .bashrc of your home directory at the end: export PATH=$PATH:/usr/local/go/bin export PATH=$PATH:$GOPATH/bin worked for me just fine! On Wednesday, October 11, 2017 at 8:04:28 AM UTC+3, Pat Farrell wrote: > > I've installed the

Re: [go-nuts] concurrent write-only to map ok?

2017-10-13 Thread Shawn Milochik
On Fri, Oct 13, 2017 at 2:05 PM, Alex Buchanan wrote: > Basically, I want to spawn a goroutine per object, objects have unique > IDs, and I want each routine to write its results to a shared map. Nothing > will be reading from the map while the goroutines are running. > > Is this safe? > > Whethe

Re: [go-nuts] concurrent write-only to map ok?

2017-10-13 Thread Ian Lance Taylor
On Fri, Oct 13, 2017 at 11:05 AM, Alex Buchanan wrote: > > Basically, I want to spawn a goroutine per object, objects have unique IDs, > and I want each routine to write its results to a shared map. Nothing will > be reading from the map while the goroutines are running. > > Is this safe? No. In

[go-nuts] concurrent write-only to map ok?

2017-10-13 Thread Alex Buchanan
Basically, I want to spawn a goroutine per object, objects have unique IDs, and I want each routine to write its results to a shared map. Nothing will be reading from the map while the goroutines are running. Is this safe? Thanks -- You received this message because you are subscribed to the

Re: [go-nuts] Crypto - modes of operation

2017-10-13 Thread Jakob Borg
On 13 Oct 2017, at 14:40, Sonia Bogos mailto:soniam.bo...@gmail.com>> wrote: Hello, I have a small crypto question. I noticed that in the "crypto/cipher" package CBC and ECB are BlockMode type while CFB,CTR,OFB are Stream type. At the basics, they are all modes of operation that allow us to e

Re: [go-nuts] Newbie Implementation of Set Partitions Generator

2017-10-13 Thread Michael Jones
Generating set partitions is efficiently performed by [the second] Algorithm H in Knuth's Art of Computer Programming, Volume 4A, Combinatorial Algorithms, Part 1. It appears on page 416. Counting the number of set partitions means evaluating the Bell numbers, which is easily done by table summati

Re: [go-nuts] Re: Why are two slices in this example less costly than one?

2017-10-13 Thread Marvin Stenger
I told you the reason already. slice of struct is in the stack frame. Am Freitag, 13. Oktober 2017 16:59:14 UTC+2 schrieb Gabriel Aszalos: > > > For some reason, it seems that allocating a slice of slices takes up quite > a bit of memory, while allocating the slice of structs takes up no memory?

Re: [go-nuts] Re: Why are two slices in this example less costly than one?

2017-10-13 Thread Gabriel Aszalos
Thanks Diego. I didn't know about the `--alloc_space` flag. Quite insightful!!! For anyone else potentially interested in the results, here they are: Here are the results for the original FieldsFunc from the standard library:

Re: [go-nuts] How to generate long int with k random bits.

2017-10-13 Thread Jan Mercl
> On Fri, Oct 13, 2017 at 4:37 PM Christian LeMoussel wrote: See https://golang.org/pkg/math/big/#Int.Rand -- -j -- 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

[go-nuts] How to generate long int with k random bits.

2017-10-13 Thread Christian LeMoussel
Hi, In python there is random. getrandbits(*k* ) that returns a python long int with *k* rando

Re: [go-nuts] Why can't I call a pointer-receiver method on a temperary but addressable struct literal?

2017-10-13 Thread Ian Lance Taylor
On Fri, Oct 13, 2017 at 5:41 AM, Cholerae Hu wrote: > package main > > import ( > "fmt" > "reflect" > ) > > type Circle struct { > radius float64 > } > > func (c *Circle) DummyMethod() { > fmt.Println("Type of receiver:", reflect.TypeOf(c)) > } > > func main() { > // error: can

Re: [go-nuts] Shutdown server over shared variable

2017-10-13 Thread Ian Lance Taylor
On Fri, Oct 13, 2017 at 3:52 AM, wrote: > > As I can understand from manuals prefered way to communicate between > gorutine is channel but in core component net/http we have shared method > Shutdown > >Why and how it work? Why autor violate language ideology by himself? There are various

Re: [go-nuts] Newbie Implementation of Set Partitions Generator

2017-10-13 Thread Ian Lance Taylor
On Thu, Oct 12, 2017 at 11:57 PM, john lynch wrote: > > I've been implementing some Python code in Go to learn the language. In > Python this will generate a Set Partition. The Go equivalent follows. > > The Go runs fine for list element sizes 2 and 3 (which means the recursion > is running prop

Re: [go-nuts] Why can't I call a pointer-receiver method on a temperary but addressable struct literal?

2017-10-13 Thread Ian Davis
On Fri, 13 Oct 2017, at 02:02 PM, Ian Davis wrote: > On Fri, 13 Oct 2017, at 01:41 PM, Cholerae Hu wrote: >> https://golang.org/ref/spec#Calls >>> If x is addressable[1] and &x's method set contains m, x.m() is >>> shorthand for (&x).m()>> >> https://golang.org/ref/spec#Address_operators >> C

Re: [go-nuts] Why can't I call a pointer-receiver method on a temperary but addressable struct literal?

2017-10-13 Thread Ian Davis
On Fri, 13 Oct 2017, at 01:41 PM, Cholerae Hu wrote: > https://golang.org/ref/spec#Calls >> If x is addressable[1] and &x's method set contains m, x.m() is >> shorthand for (&x).m()> > https://golang.org/ref/spec#Address_operators > Composite literals is addressable. > > So why can't I call Dum

[go-nuts] Why can't I call a pointer-receiver method on a temperary but addressable struct literal?

2017-10-13 Thread Cholerae Hu
package main import ( "fmt" "reflect" ) type Circle struct { radius float64 } func (c *Circle) DummyMethod() { fmt.Println("Type of receiver:", reflect.TypeOf(c)) } func main() { // error: cannot take the address of Circle literal // Circle{radius: 1.0}.DummyMethod()

[go-nuts] Newbie Implementation of Set Partitions Generator

2017-10-13 Thread john lynch
I've been implementing some Python code in Go to learn the language. In Python this will generate a Set Partition. The Go equivalent follows. The Go runs fine for list element sizes 2 and 3 (which means the recursion is running properly). Also 4 but at 5 and above it generates the intial sets

[go-nuts] Crypto - modes of operation

2017-10-13 Thread Sonia Bogos
Hello, I have a small crypto question. I noticed that in the "crypto/cipher" package CBC and ECB are BlockMode type while CFB,CTR,OFB are Stream type. At the basics, they are all modes of operation that allow us to encrypt messages with a variable length. What is the technical reason for this

[go-nuts] Shutdown server over shared variable

2017-10-13 Thread vit1251
Hello, As I can understand from manuals prefered way to communicate between gorutine is channel but in core component net/http we have shared method Shutdown Why and how it work? Why autor violate language ideology by himself? Thanks. -- You received this message because you are subsc

[go-nuts] Re: Go jobs in Canada

2017-10-13 Thread jobs jobs
Did you had the job in Canada? 在 2017年9月21日星期四 UTC+8上午11:00:50,Totoro W写道: > > Hi there, > > I'm now software developer in China and looking for a job in Canada. And I > have worked with go for at least 5 years. > Is there any opportunity there (i could relocate there if possible). I'd > like to

Re: [go-nuts] Re: Why are two slices in this example less costly than one?

2017-10-13 Thread Diego Medina
> > > This is exactly what I was trying to figure out how I would be able to do, > and more specifically, if there's an easy way to find out. > > the pprof tool can read a memory or cpu profile created during your benchmark, and then you can see details of your function, line by line, and see

Re: [go-nuts] Re: Why are two slices in this example less costly than one?

2017-10-13 Thread Gabriel Aszalos
Superb! Thank you Ian. That is indeed insightful. In my case (as can be seen in the commit message showing the benchstat output), allocations for small ASCII test cases have a delta of +860%, which is 8 times more bytes allocated. You've said: > Then you have to figure out why they are differen

Re: [go-nuts] Gomobile and SAF

2017-10-13 Thread Audrius Butkevicius
This is more work than say writing a bit of C to instantiate a JVM in the go process for example, and to get what we are after. On 13 Oct 2017 06:41, "Jakob Borg" wrote: > On 12 Oct 2017, at 23:43, audrius.butkevic...@gmail.com wrote: > > > > Your example has a MainActivity.java. > > As I said,