[go-nuts] Re: Garbage Collector triggering when deleting an object

2020-11-23 Thread tokers
Are there any documents?

On Monday, November 23, 2020 at 7:28:31 PM UTC+8 Tamás Gulácsi wrote:

> There is a runtime.SetFinalizer, but it is not guaranteed to be run, 
> anytime.
> The most idiomatic and safe solution is to have a Close() method on the Go 
> side, which frees the C side.
> You may even add a Finalizer that panics if Close haven't been called 
> before...
>
> tokers a következőt írta (2020. november 23., hétfő, 4:17:18 UTC+1):
>
>> There is a runtime.SetFinalizer function.
>>
>> On Sunday, November 22, 2020 at 8:13:22 PM UTC+8 Sean wrote:
>>
>>> I am writing a Golang wrapper for OpenAL-Soft. 
>>> I need to create some buffers. These operations are happening on the 
>>> OpenAL-Soft side (So C functions). I am loading PCM data into buffers. 
>>>
>>> Can I set up a trigger mechanism like "x.__del__" as in Python? 
>>>
>>> I can set the garbage collector to follow some objects. 
>>> But I have to call some C functions (alDeleteBuffers) to delete buffers 
>>> in OpenAL. 
>>>
>>> I want garbage collector to run this function while deleting the object. 
>>>
>>> Is this possible? 
>>>
>>>

-- 
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/97bafe0a-46a6-46ba-8aeb-fa875bf80b58n%40googlegroups.com.


[go-nuts] Re: Garbage Collector triggering when deleting an object

2020-11-22 Thread tokers
There is a runtime.SetFinalizer function.

On Sunday, November 22, 2020 at 8:13:22 PM UTC+8 Sean wrote:

> I am writing a Golang wrapper for OpenAL-Soft.
> I need to create some buffers. These operations are happening on the 
> OpenAL-Soft side (So C functions). I am loading PCM data into buffers.
>
> Can I set up a trigger mechanism like "x.__del__" as in Python?
>
> I can set the garbage collector to follow some objects.
> But I have to call some C functions (alDeleteBuffers) to delete buffers 
> in OpenAL.
>
> I want garbage collector to run this function while deleting the object.
>
> Is this possible?
>
>

-- 
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/398098b5-06bf-416b-95cc-b6efd59517dfn%40googlegroups.com.


[go-nuts] Re: builtin function definitions

2020-07-28 Thread tokers
You may try to use `go tool compile -S ` and read the assemble 
codes to find the truth.

On Wednesday, July 29, 2020 at 5:39:53 AM UTC+8 shan...@gmail.com wrote:

> Hi all, I'm trying to understand what *exactly* the .(type) is doing in 
> the following statement
>
> switch foo := bar.(type)
>
> I mean, I get that foo is being assigned a type converted version of the 
> bar interface, but, I want to see what exactly they .(type) call does.
>
> I have found 
> https://github.com/golang/go/blob/master/src/go/types/selection.go#L60 
> which I *think* is the method being called, but I am not sure.
>
> So I have two questions.
> 1) Am I looking at the correct function
> 2) (and far more importantly) How do I find which method such code is 
> calling (it's problematic for me at this point towork out what, for 
> example, something defined in builtin is really calling.
>
> Can someone point me at a resource that I have obviously overlooked?
>
>
> Note: I've seen this 
> https://stackoverflow.com/questions/18512781/built-in-source-code-location 
> and, rereading it this morning it looks like "If it's not in the runtime 
> package, start grepping the compiler packages" - is that what I should be 
> doing?
>

-- 
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/6a813c48-cacd-4916-9116-e21bcf5b7b4bn%40googlegroups.com.


Re: [go-nuts] Weird problem that CPU is nearly 100%

2020-07-23 Thread tokers
We detected this problem once again, and this time we observed the stacks.

See https://github.com/golang/go/issues/40372 for the details.

On Friday, May 22, 2020 at 3:25:39 PM UTC+8 Jan Mercl wrote:

> On Fri, May 22, 2020 at 9:05 AM tokers  wrote:
> >
> > Thanks for you reply.
> >
> > Yeah, we have the plan to upgrade our go version to 1.13.10.
>
> Note that 1.13 does not have goroutine preemption Ian was talking
> about wrt 1.14.
>

-- 
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/bf2d1f54-f520-49da-b28f-80f8a6b23269n%40googlegroups.com.


[go-nuts] Re: Allocating lots (e.g. a million) objects on the heap

2020-07-21 Thread tokers
And maybe the reuse mechanism (e.g. sync.Pool) is good for you.
On Tuesday, July 21, 2020 at 1:35:14 AM UTC+8 netconn...@gmail.com wrote:

> I have an application where I will be allocating millions of data 
> structures, all of the same size. My program will need to run continuously 
> and be pretty responsive to 
> its network peers.
>
> The data is fairly static, once allocated it will rarely need to be 
> modified or deleted.
>
> In order to minimize the garbage collection scanning overhead, I was 
> thinking of allocating large blocks on the heap that were a fixed size that 
> would hold 20K or so elements
> and then write a simple allocator to hand out pieces of those blocks when 
> needed. Instead of having to scan millions of items on the heap, the GC 
> would only be scanning 100 or so
> items.
>
> Sound reasonable?  Or does this 'go' against the golang way of doing 
> things?
>
> F
>

-- 
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/6eff37cc-9d83-4735-8530-8df40b4e72d5n%40googlegroups.com.


[go-nuts] Re: Strings with blank convert to bytes

2020-07-09 Thread tokers
Hello!

Just quote the document:

> Scanf scans text read from standard input, storing successive 
space-separated values into successive arguments as determined by the format

Instead, you can use fmt.Scanln.
On Friday, July 10, 2020 at 10:03:26 AM UTC+8 max1...@gmail.com wrote:

> Hello everyone:
> I use golang with Win10. The version of golang I used is go1.12.9.
> This  is a simple code I'm trying 
> to figure out.
> However, I have no idea how to edit to make the output "b1" the same as 
> "b" if "b1" is read from user input.
> Could anyone help me to solve this problem?
>
> Any help is appreciated.
> Thank you very much!
> Max
>

-- 
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/743538ee-b0b0-4ed0-bfc3-0a337f11ac66n%40googlegroups.com.


[go-nuts] Re: Is there a way to create a global variable inside go routine stack? so that i can access any time, without passing around between methods/functions. Crazy thought !!!..

2020-05-24 Thread tokers
You may try to inspect this go package: https://github.com/jtolio/gls

-- 
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/6cb0288c-8dda-4b24-82ca-d41c28b7ddca%40googlegroups.com.


Re: [go-nuts] Weird problem that CPU is nearly 100%

2020-05-22 Thread tokers
Thanks for you reply.

Yeah, we have the plan to upgrade our go version to 1.13.10.

-- 
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/5a4c4918-82f7-4979-9a86-8c289c25e1b8%40googlegroups.com.


[go-nuts] Weird problem that CPU is nearly 100%

2020-05-21 Thread tokers
Hi!

We have a go program (an api server) on a virtual machine(with 8 cores) 
with a long time stable running.
However, the program recently suffered a weird problem that only a single 
CPU reached 100%
usage while others were very low, in the meanwhile, the network bandwidth 
was totally zero,
also, there were a bunch of tcp connections with CLOSE_WAIT state on the 
server side.
So it seems to me that the program was busily spinning on some events and 
cannot execute our codes.

We sent a QUIT signal to it and got its goroutine stacks, there were 3000+ 
goroutines on there, only two goroutines
were running but 370 goroutines were runnable, others were blocked on the 
channel events. Unfortunately, these two gouroutine stacks
were not available since the "goroutine running on other thread".

We didn't adjust runtime.GOMAXPROCS so the default Ps in Go should be the 
number of processors, i.e. 8. In my
view, the number of running goroutines should be larger, and it seems the 
runq size was somewhat large (even we have
8 Ms which are running user goroutines, the average runq size is 46, if we 
only the global runq).

I don't know what did other Ms do at that time, I know there is a mark 
assistant mechanism in the garbage collector implementation.
But will it use a log of Ms and make the scheduler in trouble?

Go version we use: go/1.12.13.
Os we use: CentOS/3.10.0.

-- 
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/87d85095-a8f1-49e9-b079-1e9fe2089a31%40googlegroups.com.


[go-nuts] Re: Confusion about the doc for ServeMux

2020-05-14 Thread tokers

>
>
>1. "/codesearch" means a path. "codesearch.google.com/" means a host "
>codesearch.google.com" and the subtree path "/". Does it mean that the 
>latter takes precedence over the former?
>
> Yes. A pattern starts with a host will be used firstly if matching 
successfully. 

>
>1. Does *without also taking over requests for "http://www.google.com/ 
>"* mean that the handler for "
>codesearch.google.com/" does not take requests for "
>http://www.google.com/;?
>
> Yes. Pattern "codesearch.google.com/" only takes over requests which host 
is "codesearch.google.com". 

-- 
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/51988a48-90e0-41df-9310-fd7d0e2279e3%40googlegroups.com.


[go-nuts] Re: escape analysis question

2020-03-05 Thread tokers
This is a known deficiency of Go's escape analysis, which is recorded in 
this doc: 
https://docs.google.com/document/d/1CxgUBPlx9iJzkz9JWkb6tIpTe5q32QDmz8l0BouG0Cw/view#

On Thursday, March 5, 2020 at 5:58:37 AM UTC+8, burns...@gmail.com wrote:
>
> Hi All,
>
> I am trying to debug why a byte slice is escaping in my program. I have a 
> small reproducible example here:
>
> % cat escape.go
> package main
>
> func main() {
> x := make([]byte, 5)
> y := new([]byte)
> *y = x
> nothing((*y)[3])
> }
>
> func nothing(b byte) {}
> % go tool compile -m -m -l escape.go
> escape.go:4:11: make([]byte, 5) escapes to heap:
> escape.go:4:11:   flow: x = &{storage for make([]byte, 5)}:
> escape.go:4:11: from make([]byte, 5) (spill) at escape.go:4:11
> escape.go:4:11: from x := make([]byte, 5) (assign) at escape.go:4:4
> escape.go:4:11:   flow: {heap} = x:
> escape.go:4:11: from *y = x (assign) at escape.go:6:5
> escape.go:4:11: make([]byte, 5) escapes to heap
> escape.go:5:10: new([]byte) does not escape
>
> It seems to me like neither x nor it's backing array should escape, but 
> I'm having trouble figuring out why it's flagged as escaping from the debug 
> output.
>
> % go version
> go version go1.14 darwin/amd64
>
>
> Any help would be appreciated.
>
> Ethan
>
>

-- 
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/646ff0ef-2feb-409b-9ac4-8c667b40b392%40googlegroups.com.


[go-nuts] Re: mcache per P or per M?

2019-11-03 Thread tokers
Hello!

It's my own understanding and it's not necessary true.
The mcache belongs to per P, but by assigning it to M, we can mark M is 
binded to this P.

-- 
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/f8b28f93-b179-47db-984e-c179bf13080f%40googlegroups.com.


Re: [go-nuts] go runtime/stubs.go noescape

2019-10-17 Thread tokers
I did some experiments to mimic the noescape function
and modify it with/without the "exclusive-or",but it seems
no influence for the escape analysis, sigh.

-- 
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/dd140894-1e53-4788-a8d9-cd0eb8bc77e0%40googlegroups.com.


Re: [go-nuts] go runtime/stubs.go noescape

2019-10-17 Thread tokers
Yes, I'm just curious about the effect of the "exclusive or".

-- 
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/2bdeacb7-1fe1-49b0-8bec-60b85fa9bc7d%40googlegroups.com.


[go-nuts] Re: go runtime/stubs.go noescape

2019-10-12 Thread tokers
Is this operation necessary?

-- 
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/42ff0883-1ff4-436b-916c-3068f8fbe581%40googlegroups.com.


[go-nuts] go runtime/stubs.go noescape

2019-10-12 Thread tokers
Hello!

Recently I read some go source code and when I read the noescape function 
in runtime/stubs.go, I have a doubt about it.

// noescape hides a pointer from escape analysis.  noescape is
// the identity function but escape analysis doesn't think the
// output depends on the input.  noescape is inlined and currently
// compiles down to zero instructions.
// USE CAREFULLY!
//go:nosplit
func noescape(p unsafe.Pointer) unsafe.Pointer {
   x := uintptr(p)
   return unsafe.Pointer(x ^ 0)
}



I don't know what's the purpose of the exclusive or operation? Does it 
necessary?

-- 
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/35fdf376-75eb-4c58-898f-de3be915babe%40googlegroups.com.