[go-nuts] Is this a bug ?

2021-06-03 Thread Jamil Djadala

https://groups.google.com/g/golang-nuts

package main

import (
"fmt"
)

func main() {
const aa int = 0
var a int
fmt.Println(float64(1

Re: [go-nuts] I think I found a bug?

2021-05-26 Thread Jamil Djadala
minimally changed code that works:

https://play.golang.org/p/Tcfw_EC8jMp


On Thursday, May 27, 2021 at 4:11:40 AM UTC+3 johnfor...@gmail.com wrote:

> Here’s the code.  It might be 
> possible to come up with a shorter reproducer, but I’m not sure where to 
> start. The recursion takes place in line 21. The code works for 7 or 
> smaller, and fails for 8 and larger.
>
> J
>
>
> On May 26, 2021, at 20:34, Martin Schnabel  wrote:
>
> Could you send a https://play.golang.org/ link showing a short example?
>
> Without much information it sounds like a you update the same slice at two 
> different indices. It would be interesting to know how you populate the 
> temp slice.
>
> On 27.05.21 01:52, John Olson wrote:
>
> I have a recursive function that seems to be reusing memory it shouldn't. 
> I'm developing in Goland 2021.1.1 with go version 1.16.2.
> I've written a function to generate the partitions of an integer. The 
> partitions of n are all the sets of integers that add up to n, so the 
> partitions of 3 are {3}, {2,1} and {1,1,1}. As n grows, the number of 
> partitions grows exponentially (to be precise, as e^(n^½)). I wrote a 
> recursive function, which works great up to n=7. At n=8, one of the 
> partitions is {2,2,2,1}, which is obviously wrong; and since the function 
> is recursive, every subsequent n is wrong, too.
> I just spent quite a long time stepping through the code, and I found that 
> what seems to be happening is that a slice declared in my recursive 
> function is being reused in two different recursions. Specifically, my 
> function declares
> var temp [][]int
> to build up the list of partitions. When I compute Partitions(8), I have 
> to compute Partitions(4), 5, 6 and 7. I memoize each set of partitions so I 
> only have to compute them once.
> It all goes wrong when I'm working on Partitions(7). At this point, 
> Partitions(8) has already added 6 cases, the last of which is {2,2,2,2}. 
> This is stored in temp[5], the temp corresponding to n=8, of course. Then I 
> compute Partitions(7), which should create a new temp [][]int; I'll call 
> this temp//7. temp[6]//7 gets {2,2,2,1}, and at that point temp[5]//8 
> changes from {2,2,2,2} to {2,2,2,1}. The addresses of temp[6]//7 and 
> temp[5]//8 are different, but the addresses of the /elements/ of these 
> slices are the same.
> This has to be wrong.
> I suspect a bug in go, but I suppose it's possible there's a bug in 
> goland. I'm running on macOS 11.3.1, just in case that's relevant.
> I'm happy to share the source code if anyone is interested.
> Thanks,
> 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 to golang-nuts...@googlegroups.com <
> mailto:golang-nuts...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/fb9031ba-bfa0-4c92-9cb7-6ad3a8781184n%40googlegroups.com
>  <
> https://groups.google.com/d/msgid/golang-nuts/fb9031ba-bfa0-4c92-9cb7-6ad3a8781184n%40googlegroups.com?utm_medium=email_source=footer
> >.
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/de91d8a7-63eb-40aa-bf20-b1a18897fa84n%40googlegroups.com.


Re: [go-nuts] keep just 2 decimal places in a float64

2020-01-25 Thread Jamil Djadala
On Sat, 25 Jan 2020 19:14:15 -0800 (PST)
"Jason E. Aten"  wrote:

> 
> https://play.golang.org/p/87bDubJxjHO
> 
> I'd like to truncate a float64 to just 2 decimal places (in base 10),
> but math.Trunc is not helping me here... ideally I put 0.29 in and I
> get 0.29 out.
> Suggestions?  Playground examples appreciated.

you can use int types:
https://play.golang.org/p/qLnynemd3S1
-- 
Jamil Djadala

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20200126074011.0f17b4fa%40wolf.home.


Re: [go-nuts] querying whether the go command would run in module mode

2019-12-09 Thread Jamil Djadala
On Mon, 09 Dec 2019 19:57:48 +1030
Dan Kortschak  wrote:

> Thanks.
> 
> When you're not in a module it returns /dev/null on linux. I don't
> suppose this is platform independent?

Hi,
This command:
go env GOMOD

returns 1 emty line,
i dont see any /dev/null ?

-- 
Jamil Djadala

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191209114053.5bf5bd76%40beast.


Re: [go-nuts] Is anyone aware of a blocking ring buffer implementation?

2019-11-21 Thread Jamil Djadala
On Thu, 21 Nov 2019 22:37:37 -0600
Robert Engels  wrote:

> The OP specifically requested io.Reader/Writer interfaces. 
> 
> A pipe is what he wants. Not a ring buffer. (A pipe essentially has a
> ring buffer in the implementation though). 

from https://golang.org/pkg/io/#Pipe :

The data is copied directly from the Write to the corresponding Read
(or Reads); there is no internal buffering

and looking in implementation, it seems that internally Pipe is using
channel.

-- 
Jamil Djadala

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191122065315.78316d02%40wolf.home.


Re: [go-nuts] cgo memory fragmetation?

2019-10-07 Thread Jamil Djadala
On Mon, 7 Oct 2019 00:54:32 -0700 (PDT)
miha.vrhov...@gmail.com wrote:

> Hi guys,
> 
> We are having a very weird problem, where the process memory keeps
> rising, but both the pprof and valgrind report no memory leaks. But
> the RSS just keeps rising.The C part is in external so library
> 
> To be more exact, the pprof when the process becomes idle reports a
> few megabytes used and the Valgrind reports 88bytes lost(this are
> global objects) But the RSS for example is ~1G and virtual 4G+
> I've run also run the app with the GODEBUG=madvdontneed=1,gctrace=1
> but madvdontneed doesn't seem to help.
> 
> If I describe the MO of communicating with the library's API (all
> memory is allocated on the library side). 
> 
> for {
>   * initialize the processor 
>   * say to the library to create the blob of size x on it's side
>   * convert the returned pointer to a fake slice (code below)
>   * copy data to the fake slice
>   * instruct processor to do it's thing (e.g make
> calculations/compress the data,...)
>   * process the data on Go side (depending on the processor this
> either makes a copy of the data or creates a fake slice from it)
>   * destroy the processor (this frees the memory on the library's
> side)
>   * upload the data somewhere
> }
> 
> func cVoidPtrToByteSlice(data unsafe.Pointer, size int, bytes
> *[]byte) { header := (*reflect.SliceHeader)(unsafe.Pointer(bytes))
> header.Data = uintptr(data)
> header.Len = size
> header.Cap = size
> }
> 
> BR,
> Miha
> 

Hi, can you try to run your program with GOGC=10 environment ?

-- 
Jamil Djadala

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191007110422.325e6ae5%40bee.datamax.bg.


Re: [go-nuts] Re: methods on C types

2019-04-18 Thread Jamil Djadala
On Thu, 18 Apr 2019 07:44:53 -0700 (PDT)
peterGo  wrote:

> Cgo translates C types into equivalent unexported Go types.
> https://golang.org/cmd/cgo/


But then, definition of new methods on non-local types is forbidden.
Why it is enabled for cgo types ? 

-- 
Jamil Djadala

-- 
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.


Re: [go-nuts] golang tcp transport just like nc

2018-03-08 Thread Jamil Djadala
On Wed, 7 Mar 2018 19:16:33 -0800 (PST)
sucong...@gmail.com wrote:

> 
> 
> linux nc command port to golang 
> 
> 
> in nc , we can do this
> 
> echo 'my id is 1' > /tmp/1
> echo 'my id is 3' > /tmp/3
> rm -rf /tmp/2 /tmp/4
> 
> 
> 
> server
> 
> nc -l 19090 < /tmp/1 > /tmp/2
> 
> ( if you are in linux not mac this may be  ` nc -l -p 19090 `  )
> 
> client
> 
> 
> nc 127.0.0.1 19090 < /tmp/3 > /tmp/4
> 
> 
> when finish ,both server and client will be closed
> 
> client send /tmp/3 is saved by server to /tmp/2
> 
> server send /tmp/1 is saved by server to /tmp/4
> 
> then use golang do the same thing , but when finished , both server
> and client can not closed automaticly
> 
> 
> 
> echo 'my id is 1' > /tmp/1
> echo 'my id is 3' > /tmp/3
> rm -rf /tmp/2 /tmp/4
> 
> 
> 
> 
> 
> ./nc serer < /tmp/1 > /tmp/2
> 
> 
> 
> ./nc  < /tmp/3 > /tmp/4
> 
> 
> 
> please help me how to solve this and works like nc 
> 
> 
> example code 
> 
> https://gist.github.com/suconghou/a1bfab9a30b3408400b6382d73051227
> 
> 
> 

See
https://play.golang.org/p/6ljoK4EB9iY

You must use CloseRead/CloseWrite

Jamil Djadala


-- 
Jamil Djadala

-- 
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.


Re: [go-nuts] printing a struct fields that implements an error interface

2018-02-18 Thread Jamil Djadala
On Sat, 17 Feb 2018 16:05:42 -0800 (PST)
Joseph Lorenzini <jalo...@gmail.com> wrote:

> Hi all:
> 
> Per documentation:
> 
> "If an operand implements the error interface, the Error method will
> be invoked to convert the object to a string, which will then be
> formatted as required by the verb (if any)"
> 
> And this is so even if the struct implements the stringer interface.
> So if I print the struct, I get the error value. Is there anyway to
> force fmt.Print to output the struct fields, even when it implements
> the error interface? 
> 
> Thanks,
> Joe 
> 

Just use fmt.Print(v.String()) instead of fmt.Print(v)

-- 
Jamil Djadala

-- 
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.