github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/internal/util/alloc_slice.go (about)

     1  //go:build !(darwin || linux) || !(amd64 || arm64 || riscv64) || sqlite3_noshm || sqlite3_nosys
     2  
     3  package util
     4  
     5  import "github.com/tetratelabs/wazero/experimental"
     6  
     7  func sliceAlloc(cap, max uint64) experimental.LinearMemory {
     8  	return &sliceBuffer{make([]byte, cap), max}
     9  }
    10  
    11  type sliceBuffer struct {
    12  	buf []byte
    13  	max uint64
    14  }
    15  
    16  func (b *sliceBuffer) Free() {}
    17  
    18  func (b *sliceBuffer) Reallocate(size uint64) []byte {
    19  	if cap := uint64(cap(b.buf)); size > cap {
    20  		b.buf = append(b.buf[:cap], make([]byte, size-cap)...)
    21  	} else {
    22  		b.buf = b.buf[:size]
    23  	}
    24  	return b.buf
    25  }