-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
77 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/named-data/ndnd/std/ndn" | ||
"github.com/named-data/ndnd/std/types/arc" | ||
) | ||
|
||
var count = 1 | ||
|
||
// streamBufferPool is the pool of buffers used for reading streams. | ||
// When passed an Arc, downstreams must either increment it or copy the buffer. | ||
var streamBufferPool = arc.NewArcPool( | ||
func() *bytes.Buffer { | ||
count++ | ||
if count%100 == 0 { | ||
fmt.Println("StreamBufferPool: creating new buffer", count) | ||
} | ||
return &bytes.Buffer{} | ||
}, | ||
func(buf *bytes.Buffer) { | ||
buf.Reset() | ||
buf.Grow(8 * ndn.MaxNDNPacketSize) | ||
}) | ||
|
||
// streamBuffer returns a buffer from the pool. | ||
func streamBuffer() (*arc.Arc[*bytes.Buffer], []byte) { | ||
bufArc := streamBufferPool.Get() | ||
bufArc.Inc() | ||
recvBuf := bufArc.Load().AvailableBuffer() | ||
recvBuf = recvBuf[:cap(recvBuf)] | ||
return bufArc, recvBuf | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters