mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
fix memory allocation
This commit is contained in:
parent
1ee828b768
commit
b9ae16fbc5
|
@ -14,7 +14,7 @@ const (
|
||||||
|
|
||||||
func bitCount(size int) (count int) {
|
func bitCount(size int) (count int) {
|
||||||
for ; size > min_size; count++ {
|
for ; size > min_size; count++ {
|
||||||
size = size >> 1
|
size = (size + 1) >> 1
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package mem
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,6 +26,16 @@ func TestAllocateFree(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAllocateFreeEdgeCases(t *testing.T) {
|
||||||
|
assert.Equal(t, 1, bitCount(2048))
|
||||||
|
assert.Equal(t, 2, bitCount(2049))
|
||||||
|
|
||||||
|
buf := Allocate(2048)
|
||||||
|
Free(buf)
|
||||||
|
buf = Allocate(2049)
|
||||||
|
Free(buf)
|
||||||
|
}
|
||||||
|
|
||||||
func TestBitCount(t *testing.T) {
|
func TestBitCount(t *testing.T) {
|
||||||
count := bitCount(12)
|
count := bitCount(12)
|
||||||
if count != 0 {
|
if count != 0 {
|
||||||
|
|
Loading…
Reference in a new issue