// CreateBufferedQueue returns BufferedQueue.
// To start writing the buffer to redis use Start().
// Optimal BufferSize seems to be around 200.
// Works like SelectBufferedQueue for existing queues
329786
func CreateBufferedQueue(redisHost, redisPort, redisPassword string, redisDB int64, name string, bufferSize int) *BufferedQueue {
	q := CreateQueue(redisHost, redisPort, redisPassword, redisDB, name)
	return &BufferedQueue{
		Queue:        q,
		BufferSize:   bufferSize,
		Buffer:       make(chan *Package, bufferSize*2),
		flushStatus:  make(chan chan bool, 1),
		flushCommand: make(chan bool, bufferSize*2),
	}
}
649178
func reserveBuffer(buf []byte, appendSize int) []byte {
	newSize := len(buf) + appendSize
	if cap(buf) < newSize {
		// Grow buffer exponentially
		newBuf := make([]byte, len(buf)*2+appendSize)
		copy(newBuf, buf)
		buf = newBuf
	}
	return buf[:newSize]
}
74136
func (session *Session) BufferSize(size int) *Session {
	session.statement.bufferSize = size
	return session
}
850642
func NewSizedBufferPool(size int, alloc int) BufferPool {
	return bpool.NewSizedBufferPool(size, alloc)
}
254481
func (c *Conn) startWriterBuffering() {
	c.bufferedWriter = writersPool.Get().(*bufio.Writer)
	c.bufferedWriter.Reset(c.conn)
}
602076
func NewBufferPool(baseline int) *BufferPool {
	if baseline <= 0 {
		panic("baseline can't be <= 0")
	}
	p := &BufferPool{
		baseline0: baseline,
		baseline:  [...]int{baseline / 4, baseline / 2, baseline * 2, baseline * 4},
		closeC:    make(chan struct{}, 1),
	}
	for i, cap := range []int{2, 2, 4, 4, 2, 1} {
		p.pool[i] = make(chan []byte, cap)
	}
	go p.drain()
	return p
}
1220345
func NewBufferAttr() *BufferAttr {
	return &BufferAttr{
		Maxlength: ^uint32(0),
		Tlength:   ^uint32(0),
		Prebuf:    ^uint32(0),
		Minreq:    ^uint32(0),
		Fragsize:  ^uint32(0),
	}
}
909240
func NewBufferedFileWriterSize(w *FileWriter, size int, flush time.Duration) *BufferedFileWriter {
	bw := BufferedFileWriter{
		quitChan:   make(chan bool, 1),
		origWriter: w,
		bufWriter:  bufio.NewWriterSize(w, size),
	}
	go bw.flushDaemon(flush)
	return &bw
}
1076684
func NewBufferWithCapacity(capacity int) *Buffer {
	return &Buffer{
		array: make([]float64, capacity),
		head:  0,
		tail:  0,
		size:  0,
	}
}
1032576
func NewBufferedLogWriter(maxLen int) *BufferedLogWriter {
	w := &BufferedLogWriter{
		maxLen: maxLen,
		in:     make(LogRecordCh),
		out:    make(LogRecordCh),
	}
	go w.loop()
	return w
}
95702
func NewQueue() Queue {
	q := Queue{
		jobs: make([]*Package, 0),
		lock: new(sync.RWMutex),
	}

	return q
}
889339
func newBufferedChecksumWithBuffer(in hash.Hash32, bufferSize int) *BufferedChecksum {
	return &BufferedChecksum{in: in, buffer: make([]byte, bufferSize)}
}
1057997
func NewLimitedQueue(max int) Queue {
	return Queue{queue: make([]interface{}, 0, max), maxLen: max, mode: modeNormal}
}
810116
func NewBuffer(size int64) (*Buffer, error) {
	if size <= 0 {
		return nil, fmt.Errorf("Size must be positive")
	}

	b := &Buffer{
		size: size,
		data: make([]byte, size),
	}
	return b, nil
}
32906
func (t *Term) Buffered() (int, error) {
	var n int
	err := termios.Tiocoutq(uintptr(t.fd), &n)
	return n, err
}
412498
func NewBufferFrom(p []byte) *Buffer {
	buf := NewBuffer(len(p))
	buf.Write(p)
	zero(p, len(p))
	return buf
}
13940
func NewBufferStore(r Retriever, cap int) *BufferStore {
	if cap <= 0 {
		cap = DefaultTxnMembufCap
	}
	return &BufferStore{
		r:         r,
		MemBuffer: &lazyMemBuffer{cap: cap},
	}
}