Skip to content

Commit

Permalink
update go version 1.23
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Dec 14, 2024
1 parent 2f33da0 commit a1d6648
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/qjfoidnh/BaiduPCS-Go

go 1.18
go 1.23

require (
github.com/GeertJohan/go.incremental v1.0.0
Expand Down
32 changes: 3 additions & 29 deletions pcsutil/cachepool/malloc.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
package cachepool

import (
"reflect"
"unsafe"
)

//go:linkname mallocgc runtime.mallocgc
func mallocgc(size uintptr, typ uintptr, needzero bool) unsafe.Pointer

//go:linkname rawbyteslice runtime.rawbyteslice
func rawbyteslice(size int) (b []byte)

// RawByteSlice point to runtime.rawbyteslice
func RawByteSlice(size int) (b []byte) {
return rawbyteslice(size)
}

// RawMalloc allocates a new slice. The slice is not zeroed.
func RawMalloc(size int) unsafe.Pointer {
return mallocgc(uintptr(size), 0, false)
}

// RawMallocByteSlice allocates a new byte slice. The slice is not zeroed.
// RawMallocByteSlice allocates a new byte slice.
func RawMallocByteSlice(size int) []byte {
p := mallocgc(uintptr(size), 0, false)
b := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(p),
Len: size,
Cap: size,
}))
return b
bytesArray := make([]byte, size)
return bytesArray
}
10 changes: 0 additions & 10 deletions pcsutil/cachepool/malloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package cachepool_test
import (
"fmt"
"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/cachepool"
"reflect"
"runtime"
"testing"
"unsafe"
)

func TestMalloc(t *testing.T) {
Expand All @@ -20,12 +18,4 @@ func TestMalloc(t *testing.T) {
b = cachepool.RawMallocByteSlice(128)
fmt.Printf("---%s---\n", b)
runtime.GC()

b = cachepool.RawByteSlice(128)
fmt.Println(b)
runtime.GC()

b = cachepool.RawByteSlice(127)
bH := (*reflect.SliceHeader)(unsafe.Pointer(&b))
fmt.Printf("%#v\n", bH)
}

0 comments on commit a1d6648

Please sign in to comment.