| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package main |
| 14 |
|
| 15 |
import ( |
| 16 |
"log" |
| 17 |
"math/rand" |
| 18 |
"time" |
| 19 |
|
| 20 |
"golang.org/x/exp/mmap" |
| 21 |
) |
| 22 |
|
| 23 |
var garbage []byte |
| 24 |
|
| 25 |
func main() { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
const filename = "manual_test_program.go" |
| 31 |
|
| 32 |
for _, explicitClose := range []bool{false, true} { |
| 33 |
r, err := mmap.Open(filename) |
| 34 |
if err != nil { |
| 35 |
log.Fatalf("Open: %v", err) |
| 36 |
} |
| 37 |
println("Open succeeded; Len =", r.Len()) |
| 38 |
if explicitClose { |
| 39 |
r.Close() |
| 40 |
} else { |
| 41 |
|
| 42 |
|
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
println("Finished all explicit Close calls.") |
| 47 |
println("Creating and collecting garbage.") |
| 48 |
println("Look for two munmap log messages.") |
| 49 |
println("Hit Ctrl-C to exit.") |
| 50 |
|
| 51 |
rng := rand.New(rand.NewSource(1)) |
| 52 |
now := time.Now() |
| 53 |
for { |
| 54 |
garbage = make([]byte, rng.Intn(1<<20)) |
| 55 |
if time.Since(now) > 1*time.Second { |
| 56 |
now = time.Now() |
| 57 |
print(".") |
| 58 |
} |
| 59 |
} |
| 60 |
} |