Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufPool is meaningless actually #180

Open
divanodestiny opened this issue May 17, 2021 · 0 comments
Open

BufPool is meaningless actually #180

divanodestiny opened this issue May 17, 2021 · 0 comments

Comments

@divanodestiny
Copy link
Contributor

divanodestiny commented May 17, 2021

code

func (db *txnDB) Insert(ctx context.Context, table string, key string, values map[string][]byte) error { // Simulate TiDB data	buf := db.bufPool.Get()	defer db.bufPool.Put(buf)
	rowData, err := db.r.Encode(buf.Bytes(), values)
	// ...
}

pass buf.Bytes() as param and append bytes to it in method Encode will never change the underlaid slice of buf, and you never initial the underlaid slice so that it always nil actually.

you can try the test code below to check

func TestBufPool(t *testing.T) {
	bufPool := util.NewBufPool()
	buf := bufPool.Get()
	defer func() {
		fmt.Println(buf.Cap())
		bufPool.Put(buf)
	}()
	str := string(appendSomething(buf.Bytes()))
	fmt.Println(str)
}

func appendSomething(bs []byte) []byte{
	return append(bs, []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant