// AllocBuffer allocates a buffer on the server
435335
func (c *Client) AllocBuffer(frames, channels int) (*Buffer, error) {
	buf, err := c.sendBufAllocMsg(frames, channels)
	if err != nil {
		return nil, err
	}
	if err := c.awaitBufAllocReply(buf); err != nil {
		return nil, err
	}
	return buf, nil
}
1071273
func (p *IntBlockPool) NextBuffer() {
	if 1+p.bufferUpto == len(p.Buffers) {
		newBuffers := make([][]int, len(p.Buffers)+len(p.Buffers)/2)
		copy(newBuffers, p.Buffers)
		p.Buffers = newBuffers
	}
	p.Buffer = p.allocator.allocate()
	p.Buffers[1+p.bufferUpto] = p.Buffer
	p.bufferUpto++

	p.IntUpto = 0
	p.IntOffset += INT_BLOCK_SIZE
}
178950
func (d *Context) PushBuffer(size int, dynamic bool) unsafe.Pointer {
	var __dynamic__ int
	if dynamic {
		__dynamic__ = 1
	}
	return C._duk_push_buffer(d.duk_context, C.duk_size_t(size), C.duk_bool_t(__dynamic__))
}
248397
func (e *PerfEvent) allocateBuffers() {
	// C.malloc() will crash the program if allocation fails, skip check:
	// https://golang.org/cmd/cgo/
	e.state = C.malloc(C.size_t(unsafe.Sizeof(C.struct_read_state{})))
	e.buf = C.malloc(C.size_t(e.pagesize))
}
568591
func (b *packetBuffer) all() []*packet {
	var a []*packet
	for p := b.root; p != nil; p = p.next {
		if p.p != nil {
			a = append(a, p.p)
		}
	}
	return a
}
707373
func (f *FileRotator) writeToBuffer(p []byte) (int, error) {
	f.bufLock.Lock()
	defer f.bufLock.Unlock()
	return f.bufw.Write(p)
}
582931
func (c *Configuration) PromoteBuffer(size uint32) *Configuration {
	c.promoteBuffer = int(size)
	return c
}
928395
func (b *Buffer) Alloc(n int) []byte {
	if n < 0 {
		panic("leveldb/util.Buffer.Alloc: negative count")
	}
	m := b.grow(n)
	return b.buf[m:]
}
606281
func (c *Context) IsRenderbuffer(renderbuffer *js.Object) bool {
	return c.Call("isRenderbuffer", renderbuffer).Bool()
}
896527
func NewBuffer() Buffer {
	b := buffer{
		observers: make(map[BufferObserver]bool),
	}
	b.SerializedBuffer.init(&rebalancingNode{})
	r := &b
	runtime.SetFinalizer(r, func(b *buffer) { b.Close() })

	return r
}
425001
func (b *buffer) takeCompleteBuffer() ([]byte, error) {
	if b.length > 0 {
		return nil, ErrBusyBuffer
	}
	return b.buf, nil
}
390508
func (f *Fluent) appendBuffer(msg *msgToSend) error {
	select {
	case f.pending <- msg:
	default:
		return fmt.Errorf("fluent#appendBuffer: Buffer full, limit %v", f.Config.BufferLimit)
	}
	return nil
}
11955
func (d *Context) ResizeBuffer(index int, newSize int) unsafe.Pointer {
	return C.duk_resize_buffer(d.duk_context, C.duk_idx_t(index), C.duk_size_t(newSize))
}
950380
func readBuffer(copyTo chan<- []byte, socketRead io.ReadCloser, batchSize int, workSize int) {
	defer close(copyTo)
	for {
		batch := make([]byte, batchSize)
		size, err := socketRead.Read(batch)
		if err == nil && workSize != 0 && size%workSize != 0 {
			var lsize int
			lsize, err = io.ReadFull(
				socketRead,
				batch[size:size+workSize-(size%workSize)])
			size += lsize
		}
		if size > 0 {
			if err != nil && workSize != 0 {
				size -= (size % workSize)
			}
			copyTo <- batch[:size]
		}
		if err != nil {
			if err != io.EOF {
				log.Print("Error encountered in readBuffer:", err)
			}
			return
		}
	}
}
1145708
func NewBuffer(f Format) *Buffer {
	return &Buffer{f: f, tmp: make([]byte, f.Width())}
}
1207657
func NewBuffer(name string, capacity int) *Buffer {
	b := &Buffer{
		buf:   make([]telegraf.Metric, capacity),
		first: 0,
		last:  0,
		size:  0,
		cap:   capacity,

		MetricsAdded: selfstat.Register(
			"write",
			"metrics_added",
			map[string]string{"output": name},
		),
		MetricsWritten: selfstat.Register(
			"write",
			"metrics_written",
			map[string]string{"output": name},
		),
		MetricsDropped: selfstat.Register(
			"write",
			"metrics_dropped",
			map[string]string{"output": name},
		),
		BufferSize: selfstat.Register(
			"write",
			"buffer_size",
			map[string]string{"output": name},
		),
		BufferLimit: selfstat.Register(
			"write",
			"buffer_limit",
			map[string]string{"output": name},
		),
	}
	b.BufferSize.Set(int64(0))
	b.BufferLimit.Set(int64(capacity))
	return b
}
1246720
func (bf *BufferFactory) ReturnBuffer(buf *bytes.Buffer) {
	bf.Return(buf.Bytes())
}