Created
November 20, 2013 03:52
递归没有GC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"net" | |
"os" | |
"runtime" | |
"time" | |
) | |
var debug bool | |
var store []byte | |
func main() { | |
store = make([]byte, 1024) | |
//debug = true | |
go Summary() | |
//for { | |
Get() | |
//} | |
} | |
func Get() { | |
conn, err := net.Dial("tcp", "10.1.1.132:80") | |
check(err) | |
_, err = conn.Write([]byte("hi!")) | |
check(err) | |
sum := 0 | |
for { | |
n, err := conn.Read(store) | |
sum += n | |
if n == 0 { | |
break | |
} | |
if err != nil { | |
fmt.Println(err) | |
if err == io.EOF { | |
break | |
} | |
return | |
} | |
} | |
conn.Close() | |
if debug { | |
fmt.Println(sum) | |
} | |
Get() | |
} | |
func check(err error) { | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(0) | |
} | |
} | |
func Summary() { | |
var m runtime.MemStats | |
for { | |
time.Sleep(100 * time.Millisecond) | |
runtime.ReadMemStats(&m) | |
fmt.Println("HeapSys:", m.HeapSys) | |
fmt.Println("HeapAlloc:", m.HeapAlloc) | |
fmt.Println("HeapIdle:", m.HeapIdle) | |
fmt.Println("HeapReleased:", m.HeapReleased) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment