Re: [go-nuts] Re: How to pass Go []byte (arrays/slices) as C *char to C functions

2018-01-24 Thread 'Bryan C. Mills' via golang-nuts
On Wed, Jan 24, 2018 at 3:00 PM, Christian LeMoussel <cnh...@gmail.com> wrote: > Thank you Bryan for your advice. > In examples, I see how to pass the Go pointers directly. > > For example : > h := C.CString(name) > defer C.free(unsafe.Pointer(h)) > gerrno,

Re: [go-nuts] Re: How to pass Go []byte (arrays/slices) as C *char to C functions

2018-01-24 Thread 'Bryan Mills' via golang-nuts
It may be considerably more efficient to pass the Go pointers directly. To do so, you may need to convert through unsafe.Pointer. Note that many C APIs that take a char* expect it to be null-terminated, so if you take that approach you may need to append an extra 0 to the slice.

Re: [go-nuts] Is it reasonable?

2018-01-08 Thread 'Bryan Mills' via golang-nuts
On Sunday, January 7, 2018 at 6:09:45 AM UTC-5, Jan Mercl wrote: > > On Sun, Jan 7, 2018 at 11:57 AM T L > wrote: > > Yes. The choice is to raise a runtime error or not. When not, the value > does not really matter because every value of an integer variable > represents an

Re: [go-nuts] Channels vs Callbacks in API

2018-01-02 Thread 'Bryan Mills' via golang-nuts
In some cases, a synchronous callback can be a fine choice: consider filepath.Walk . A synchronous callback does not require any extra goroutines, and if the caller needs to adapt it to work with a channel (or perform longer-duration processing

[go-nuts] Re: Sending C array over gob ; decoding shows wrong data

2017-12-19 Thread 'Bryan Mills' via golang-nuts
Per https://golang.org/pkg/encoding/gob/, “Structs encode and decode only exported fields.” The fields of your C struct are unexported in Go, since they start with lower-case letters. If the gob package is encoding or decoding the non-array fields of the struct, *that* is the bug. On Monday,

Re: [go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-15 Thread 'Bryan C. Mills' via golang-nuts
You can ignore the vet warning if you are certain that the uintptr values you are converting to unsafe.Pointer are *valid pointers* (i.e., not non-pointer sentinel values) that point *outside the Go heap*. It sounds like that is probably the case, but you might want to check with someone more

Re: [go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-15 Thread 'Bryan C. Mills' via golang-nuts
<https://godoc.org/golang.org/x/sys/windows#CertEnumCertificatesInStore>? I don't really know anything about Windows system calls, but it does seem like those allocate memory somewhere outside of the Go heap. On Fri, Dec 15, 2017 at 1:54 AM, snmed <sandro.p.da...@gmail.com>

[go-nuts] Re: Mapping C pointer to BYTE to golang []byte

2017-12-14 Thread 'Bryan Mills' via golang-nuts
In this case, the vet tool is correct if you're making the syscall with Go-allocated memory. The Go runtime is allowed to move values around: the address of a Go variable is only pinned for the duration of the syscall itself. If you've got C-allocated memory (or statically-allocated memory),

[go-nuts] Re: Should an empty append be an error ?

2017-12-04 Thread 'Bryan Mills' via golang-nuts
The spec defines `append` as a variadic function, with a type of the form append(s S, x ...T) S // T is the element type of S Variadic functions, in general, accept zero or more parameters. (Consider fmt.Println().) In order to reject empty appends, append would either have to have its own

Re: [go-nuts] chan chan Job per worker vs. single chan Job

2017-11-28 Thread 'Bryan Mills' via golang-nuts
Why have long-lived worker goroutines at all? If you're just trying to limit the number of jobs in flight, a semaphore is usually simpler. (A `chan struct{}` or `chan bool` works fine as a simple semaphore; for more complex use-cases, there are several semaphore packages on godoc.org.

[go-nuts] Re: How to convert from []byte to []uint32?

2017-11-13 Thread 'Bryan Mills' via golang-nuts
without copying the whole string would be slightly more complex, but as Howard noted, Go style is generally to prefer simpler code.) On Monday, November 13, 2017 at 5:31:22 PM UTC-8, peterGo wrote: > > Bryan, > > Use the test case from the question: buffer := "83f982d600c1ca

[go-nuts] Re: How to convert from []byte to []uint32?

2017-11-13 Thread 'Bryan Mills' via golang-nuts
In this case, the "code golf" solution seems clearer: https://play.golang.org/p/Jxkf2Vheml On Monday, November 13, 2017 at 3:57:57 PM UTC-8, peterGo wrote: > > Christian, > > Your specialized convertCharToInt32 function, which returns []uint32, is > slow in comparison to a more general

[go-nuts] Re: NaN as key in map

2017-11-10 Thread 'Bryan Mills' via golang-nuts
On Friday, November 10, 2017 at 5:24:25 PM UTC-5, Stefan Nilsson wrote: > > NaN is not equal to NaN. This means that if you use NaN as a key in a > map[float64]string you will not be able to retrieve it again: > https://play.golang.org/p/A7KGgoM3o6 > I guess this is the way it should be, but

Re: [go-nuts] is this code thread safety?

2017-11-03 Thread 'Bryan Mills' via golang-nuts
In general you can use the race detector to help answer this sort of question, although it does not detect all races. Unfortunately, it doesn't detect this one. (I've filed https://golang.org/issue/22569, because I think it should.) On Friday, November 3, 2017 at 4:08:19 AM UTC-4, sheepbao

Re: [go-nuts] Re: How to know if interface{} data is nil w/o reflecting?

2017-11-01 Thread 'Bryan Mills' via golang-nuts
On Wednesday, November 1, 2017 at 10:32:21 AM UTC-4, Ian Lance Taylor wrote: > > On Wed, Nov 1, 2017 at 4:18 AM, wrote: > > > > Ayan, imagine I am part of a development team. In our program I have a > > pointer r: > > > > r *myType > > > > My variable r can be nil,

[go-nuts] Re: Make error handling less verbose with Zig %% operator and %return expression?

2017-10-17 Thread 'Bryan Mills' via golang-nuts
There are lots of similar proposals in the issue tracker. Of those, https://golang.org/issue/21161 seems to have the most traffic. On Tuesday, October 17, 2017 at 5:09:33 PM UTC-4, Nicolas Grilly wrote: > > I just read about Zig, a new programming language designed to replace C. > > The error

[go-nuts] Re: Compile-time parameters in Zig: a possible solution to generic functions and data structures in Go?

2017-10-17 Thread 'Bryan Mills' via golang-nuts
On Tuesday, October 17, 2017 at 4:52:55 PM UTC-4, Nicolas Grilly wrote: > > Hello, > > I just read about the concept of compile-time parameters in Zig (a new > programming language designed to replace C): > > >

Re: [go-nuts] Sync pool old data

2017-10-12 Thread 'Bryan Mills' via golang-nuts
On Wednesday, October 11, 2017 at 4:03:30 PM UTC-4, Ian Lance Taylor wrote: > > if the number of parallel operations does not vary > significantly, a freelist is a simpler and more effective technique. > A freelist might be simpler, but it isn't necessarily more effective. sync.Pool combines

Re: [go-nuts] when to use Sync pool

2017-10-09 Thread 'Bryan Mills' via golang-nuts
On Friday, October 6, 2017 at 5:32:06 PM UTC-4, Ian Lance Taylor wrote: > > On Fri, Oct 6, 2017 at 1:23 PM, XXX ZZZ > wrote: > > > > So we are making a platform where we have to use a TON of short lived > > structs, in order to optimize this we intend to use sync pool,

[go-nuts] Re: Problems buildding go from source, tests "hangs"

2017-08-02 Thread 'Bryan C. Mills' via golang-nuts
What is the output of `$(go env CC) --version` on your machine?` On Wednesday, August 2, 2017 at 8:31:37 AM UTC-4, SauliusGurklys wrote: > > Hi, > > while building go from source: > > cd /usr/local/src/go > ./clean.bash > ./all.bash > > build succeeds without any problem and then when tests are

[go-nuts] Re: [golang-dev] Binding receiver object to a method expression, to get a method value

2017-01-18 Thread Bryan Chan
On Wednesday, 18 January 2017 16:39:03 UTC-5, rog wrote: > > On 18 January 2017 at 18:45, Bryan Chan <brya...@gmail.com > > wrote: > > But I couldn't find a way to bind a receiver to a method expression, > such > > that the resulting method value can be

[go-nuts] golang.org/x/text/transform.Chain is not thread safe

2016-06-20 Thread Bryan Reynaert
lease comment. Regards Bryan -- 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.

<    1   2