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

queue new issue #160

Closed
zuzuviewer opened this issue Sep 11, 2019 · 2 comments
Closed

queue new issue #160

zuzuviewer opened this issue Sep 11, 2019 · 2 comments

Comments

@zuzuviewer
Copy link

zuzuviewer commented Sep 11, 2019

func NewBytesQueue(initialCapacity int, maxCapacity int, verbose bool) *BytesQueue {
	return &BytesQueue{
		array:           make([]byte, initialCapacity),
		capacity:        initialCapacity,
		maxCapacity:     maxCapacity,
		headerBuffer:    make([]byte, headerEntrySize),
		tail:            leftMarginIndex,
		head:            leftMarginIndex,
		rightMargin:     leftMarginIndex,
		verbose:         verbose,
		initialCapacity: initialCapacity,
	}
}

array and headerBuffer use make to initalize, but the second param of make is len, if initialCapacity means capactiy, it shoud be use as third param(make([]byte,0,initialCapacity))

@cristaloleg
Copy link
Collaborator

Nice catch @zuzuviewer.

Well the problem is related only to variables names, looking down the code (https://github.com/allegro/bigcache/blob/master/queue/bytes_queue.go) we can see that there is no usage of append func over array.

If you think it will be better to rename NewBytesQueue params to something less tricky I encourage you to make a pull request 😉

@zuzuviewer
Copy link
Author

zuzuviewer commented Sep 11, 2019

Nice catch @zuzuviewer.

Well the problem is related only to variables names, looking down the code (https://github.com/allegro/bigcache/blob/master/queue/bytes_queue.go) we can see that there is no usage of append func over array.

If you think it will be better to rename NewBytesQueue params to something less tricky I encourage you to make a pull request 😉

@cristaloleg, I look this just now, so I can't pull right now. Maybe I can pull request few days later. But now I see some func use this capacity, for example func (q *BytesQueue) availableSpaceAfterTail() int, I think there ensure use it as capacity

@cristaloleg cristaloleg self-assigned this Jul 1, 2020
@cristaloleg cristaloleg removed their assignment Jul 1, 2020
siennathesane pushed a commit that referenced this issue Nov 4, 2020
* Fix iterator styling issues (#247)

Issues reported in #246

* fix #160 (#246)

* Update to latest golang (#248)

Co-authored-by: Oleg Kovalov <[email protected]>

* inital prep for v3.

Signed-off-by: Mike Lloyd <[email protected]>

* Use uint64 intead of uint32

There are posibility we run into a problem of int32 overflow.
To prevent this let's use uint64 everywhere.

https://github.com/allegro/bigcache/blob/21e5ca5c3d539f94e8dc563350acd97c5400154f/shard.go#L138

Fixes: #148

* Fix CI

* Do not run on 1.13

* Do not run long test

* Optimze append (#249)

* Add Benchmark for append

* Optimize Append and halve byte copies

* Optimize Append by reducing allocs

* Optimize Append by reducing allocs

* Reduces allocs from test construct

Co-authored-by: Fabian Gärtner <[email protected]>

Co-authored-by: S@P <[email protected]>
Co-authored-by: Oleg Kovalov <[email protected]>
Co-authored-by: Mike Lloyd <[email protected]>
Co-authored-by: Fabianexe <[email protected]>
Co-authored-by: Fabian Gärtner <[email protected]>
siennathesane pushed a commit that referenced this issue Nov 4, 2020
* Fix iterator styling issues (#247)

Issues reported in #246

* fix #160 (#246)

* Update to latest golang (#248)

Co-authored-by: Oleg Kovalov <[email protected]>

* inital prep for v3.

Signed-off-by: Mike Lloyd <[email protected]>

* Use uint64 intead of uint32

There are posibility we run into a problem of int32 overflow.
To prevent this let's use uint64 everywhere.

https://github.com/allegro/bigcache/blob/21e5ca5c3d539f94e8dc563350acd97c5400154f/shard.go#L138

Fixes: #148

* Fix CI

* Do not run on 1.13

* Do not run long test

* Optimze append (#249)

* Add Benchmark for append

* Optimize Append and halve byte copies

* Optimize Append by reducing allocs

* Optimize Append by reducing allocs

* Reduces allocs from test construct

Co-authored-by: Fabian Gärtner <[email protected]>

Co-authored-by: S@P <[email protected]>
Co-authored-by: Oleg Kovalov <[email protected]>
Co-authored-by: Mike Lloyd <[email protected]>
Co-authored-by: Fabianexe <[email protected]>
Co-authored-by: Fabian Gärtner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants