How much memory is allocated for the pipe created by io.pipe()?

Pipe creates a synchronous in-memory pipe, returns pipe reader and writer which makes the read/write operation in parallel.
here is the documentation :

But, I didn’t get much info about the memory consummation by the pipe.

io.Pipe() has this implementation:

func Pipe() (*PipeReader, *PipeWriter) {
	p := &pipe{
		wrCh: make(chan []byte),
		rdCh: make(chan int),
		done: make(chan struct{}),
	return &PipeReader{p}, &PipeWriter{p}

The io.pipe type is simple:

type pipe struct {
	wrMu sync.Mutex // Serializes Write operations
	wrCh chan []byte
	rdCh chan int

	once sync.Once // Protects closing done
	done chan struct{}
	rerr atomicError
	werr atomicError

So far, there is not much memory allocated.


cool. Thanks :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.