File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "encoding/json"
5+ "fmt"
46 "reflect"
57)
68
79type MyType struct {
810 Name string `json:"name"`
11+ Address
12+ }
13+ type Address struct {
14+ City string `json:"city"`
915}
10-
1116func main () {
12- mt := MyType {Name : "test" }
17+ mt := MyType {Name : "test" ,Address : Address {City : "shanghai" }}
18+ b , _ := json .Marshal (& mt )
19+ fmt .Println (string (b ))
1320 myType := reflect .TypeOf (mt )
1421 name := myType .Field (0 )
1522 tag := name .Tag .Get ("json" )
Original file line number Diff line number Diff line change @@ -10,10 +10,11 @@ import (
1010
1111func main () {
1212 // only loop 10 times to avoid exhausting the host memory
13+ holder := []* C.char {}
1314 for i := 1 ; i <= 10 ; i ++ {
14- // allocMemory malloc and memset 100Mb per time
1515 fmt .Printf ("Allocating %dMb memory, raw memory is %d\n " , i * 100 , i * 100 * 1024 * 1025 )
16- C .allocMemory ()
16+ // hold the memory, otherwise it will be freed by GC
17+ holder = append (holder , (* C .char )(C .allocMemory ()))
1718 time .Sleep (time .Minute )
1819 }
1920}
You can’t perform that action at this time.
0 commit comments