Ejemplo n.º 1
0
// NewBufferedByteSliceWrapper create a new BufferedByteSliceWrapper
func NewBufferedByteSliceWrapper(size, alloc int) *BufferedByteSliceWrapper {
	if size < 1 {
		panic("buffer number should be > 0")
	}
	if alloc < 1 {
		panic("buffer size should be > 0")
	}
	return &BufferedByteSliceWrapper{bpool.NewSizedBufferPool(size, alloc)}
}
Ejemplo n.º 2
0
// NewBufferedByteSliceWrapper2 could pre-alloc space according to length of slice and width
func NewBufferedByteSliceWrapper2(size int, length, width int) *BufferedByteSliceWrapper {
	if size < 1 {
		// panic("buffer number should be > 0")
		size = 1
	}
	if length < 1 {
		// panic("buffer size should be > 0")
		length = 1
	}
	if width <= 0 {
		return NewBufferedByteSliceWrapper(size, length)
	}
	var lines int
	if length%width == 0 {
		lines = length/width - 1
	} else {
		lines = int(length / width)
	}
	return &BufferedByteSliceWrapper{bpool.NewSizedBufferPool(size, length+lines)}
}