Compare commits
2 Commits
3d0d8ce676
...
f00dcafac4
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f00dcafac4 | ||
![]() |
4ea320c784 |
@@ -5,17 +5,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BufferPoolManager struct {
|
type BufferPoolManager struct {
|
||||||
pools map[int]*sync.Pool
|
pools map[uint]*sync.Pool
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBufferPoolManager() *BufferPoolManager {
|
func NewBufferPoolManager() *BufferPoolManager {
|
||||||
return &BufferPoolManager{
|
return &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bpm *BufferPoolManager) GetBuffer(size int) *([]uint8) {
|
func (bpm *BufferPoolManager) GetBuffer(size uint) *([]uint8) {
|
||||||
bpm.mu.Lock()
|
bpm.mu.Lock()
|
||||||
pool, exists := bpm.pools[size]
|
pool, exists := bpm.pools[size]
|
||||||
if !exists {
|
if !exists {
|
||||||
@@ -32,7 +32,7 @@ func (bpm *BufferPoolManager) GetBuffer(size int) *([]uint8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bpm *BufferPoolManager) PutBuffer(buf *([]uint8)) {
|
func (bpm *BufferPoolManager) PutBuffer(buf *([]uint8)) {
|
||||||
size := len(*buf)
|
size := uint(len(*buf))
|
||||||
bpm.mu.Lock()
|
bpm.mu.Lock()
|
||||||
pool, exists := bpm.pools[size]
|
pool, exists := bpm.pools[size]
|
||||||
if !exists {
|
if !exists {
|
||||||
@@ -41,7 +41,6 @@ func (bpm *BufferPoolManager) PutBuffer(buf *([]uint8)) {
|
|||||||
}
|
}
|
||||||
bpm.mu.Unlock()
|
bpm.mu.Unlock()
|
||||||
|
|
||||||
// Reset buffer (optional)
|
|
||||||
for i := range *buf {
|
for i := range *buf {
|
||||||
(*buf)[i] = 0
|
(*buf)[i] = 0
|
||||||
}
|
}
|
||||||
|
@@ -60,9 +60,9 @@ type (
|
|||||||
SUBMIT_MULTI_RESP struct{}
|
SUBMIT_MULTI_RESP struct{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *SUBMIT_SM) Encode() ([]byte, error) {
|
func (p *SUBMIT_SM) Encode() (*[]byte, error) {
|
||||||
buf := make([]byte, p.Size())
|
buf := ByteBufferPool.GetBuffer(uint(p.Size()))
|
||||||
err := p.EncodeInto(&buf)
|
err := p.EncodeInto(buf)
|
||||||
return buf, err
|
return buf, err
|
||||||
}
|
}
|
||||||
func (p *SUBMIT_SM) EncodeInto(buf *[]byte) error {
|
func (p *SUBMIT_SM) EncodeInto(buf *[]byte) error {
|
||||||
|
Reference in New Issue
Block a user