コード例 #1
0
func parallelRead() (int, error) {
	mf, err := mmap.Open(bigFile)
	if err != nil {
		return 0, err
	}
	defer mf.Close()

	ch := make(chan int, 4)

	whole := mf.Data()
	for i := 0; i < 4; i++ {
		go func(b []byte) {
			ch <- countZero(b)
		}(whole[i*unitSize : (i+1)*unitSize-1])
	}

	cnt := 0
	for i := 0; i < 4; i++ {
		select {
		case c := <-ch:
			cnt += c
		}
	}

	return cnt, nil
}
コード例 #2
0
func sequentialRead() (int, error) {
	mf, err := mmap.Open(bigFile)
	if err != nil {
		return 0, err
	}
	defer mf.Close()

	return countZero(mf.Data()), nil
}