eld Z of (*b) is beyond the
memory that was allocated
on the heap or reserved on the stack for a.
On Tuesday, August 14, 2018 at 9:57:05 PM UTC+8, Marvin Renich wrote:
>
> * sheepbao > [180813 23:45]:
> > go version
> > go version go1.10.2 darwin/amd64
> >
> >
I just want to research how golang func stack work.
On Tuesday, August 14, 2018 at 12:46:59 PM UTC+8, kortschak wrote:
>
> Why would you expect this to work?
>
> On Mon, 2018-08-13 at 20:44 -0700, sheepbao wrote:
> > go version
> > go version go1.10.2 darwin/a
and I change one line code, than program does not panic.
func TestPoint(t *testing.T) {
type A struct {
X int
Y string
}
type B struct {
X int
Y string
Z string
}
a := A{X: 2, Y: "yy"}
b := (*B)(unsafe.Pointer(&a))
b.Z = "zz"
go version
go version go1.10.2 darwin/amd64
test code:
func TestPoint(t *testing.T) {
type A struct {
X int
Y string
}
type B struct {
X int
Y string
Z string
}
a := A{X: 2, Y: "yy"}
b := (*B)(unsafe.Pointer(&a))
b.Z = "zz"
I wrote this code add.go:
package asm
func add(a, b int) int {
return a + b
}
then I compile this code to asm:
go tool compile -S add.go
the output is:
"".add STEXT nosplit size=19 args=0x18 locals=0x0
0x 0 (add.go:3) TEXT"".add(SB), NOSPLIT, $0-24
0x 0 (add.go:3) FUN
(k, v)
delete(m, 2)
// m = nil
}
}
// output:
// 1 1
On Tuesday, January 16, 2018 at 10:48:45 AM UTC+8, Kevin Powick wrote:
>
>
>
> On Monday, 15 January 2018 21:23:40 UTC-5, sheepbao wrote:
>>
>> I wrote this code, and why `map=nil` don't
I wrote this code, and why `map=nil` don't stop the loop?
```go
func mapTest() {
m := map[int]int{1: 1, 2: 2}
for k, v := range m {
println(k, v)
m = nil
}
}
```
output:
1 1
2 2
I don't understand when I set `m = nil`, the loop is not stop. m doesn't
seem
func isClose() bool {
select {
case <-closeChan:
return true
default:
return false
}
}
在 2017年11月7日星期二 UTC+8上午8:59:51,Albert Tedja写道:
>
> So, I just found out that closed channels always yield the zero value.
> That means, a closed channel inside a select st
Thanks, I got it.
On Friday, November 3, 2017 at 11:26:31 AM UTC+8, Jesse McNelis wrote:
>
> On Thu, Nov 2, 2017 at 4:54 PM, sheepbao >
> wrote:
> >
> > the close function is thread safety? how about call `closed` at the same
> > time.
>
> It's no
package main
import "time"
import "fmt"
import "sync/atomic"
func main() {
die := make(chan struct{})
i := int32(0)
closed := func() {
select {
case <-die:
atomic.AddInt32(&i, 1)
default:
close(die)
fmt.Println("closed")
}
is golang has any like this represents a bit in struct in c language :
struct tcphdr {
uint16_t sport;
uint16_t dport;
uint32_t seq;
uint32_t ack_seq;
uint8_t rsvd : 4;
uint8_t hl : 4;
uint8_t fin : 1,
syn : 1,
rst : 1,
psh : 1,
ack : 1,
urg : 1,
ece : 1,
cwr : 1;
uint16_t win;
uint16_t csum;
uin
I have the same result in the Mac, go 1.7.1
```go
BenchmarkMemclr_100-4 1 22.8 ns/op
BenchmarkLoop_100-4 3000 47.1 ns/op
BenchmarkMemclr_1000-4 1000 181 ns/op
BenchmarkLoop_1000-4 500 365 ns/op
BenchmarkMemclr_1-4
12 matches
Mail list logo