Skip to content

Commit 6bd3861

Browse files
author
Noam Preil
committed
switch to []unsafe.Pointer
1 parent c708c6d commit 6bd3861

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

arrow/ipc/message.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"io"
2323
"sync/atomic"
24+
"unsafe"
2425

2526
"github.com/apache/arrow-go/v18/arrow/internal/debug"
2627
"github.com/apache/arrow-go/v18/arrow/internal/flatbuf"
@@ -86,7 +87,7 @@ func NewMessage(meta, body *memory.Buffer) *Message {
8687
body: body,
8788
}
8889
m.Refcount.Buffers = []**memory.Buffer{&m.meta, &m.body}
89-
m.Additional = func() { m.msg = nil }
90+
m.Derived = []unsafe.Pointer{unsafe.Pointer(&m.msg)}
9091
m.Retain()
9192
return m
9293
}
@@ -102,7 +103,7 @@ func newMessageFromFB(meta *flatbuf.Message, body *memory.Buffer) *Message {
102103
body: body,
103104
}
104105
m.Refcount.Buffers = []**memory.Buffer{&m.meta, &m.body}
105-
m.Additional = func() { m.msg = nil }
106+
m.Derived = []unsafe.Pointer{unsafe.Pointer(&m.msg)}
106107
m.Retain()
107108
return m
108109
}

arrow/memory/refcount.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package memory
22

33
import (
44
"sync/atomic"
5+
"unsafe"
56

67
"github.com/apache/arrow-go/v18/arrow/internal/debug"
78
)
@@ -10,7 +11,7 @@ type Refcount struct {
1011
count atomic.Int64
1112
Dependencies []**Refcount
1213
Buffers []**Buffer
13-
Additional func()
14+
Derived []unsafe.Pointer
1415
}
1516

1617
func (r *Refcount) Retain() {
@@ -30,8 +31,8 @@ func (r *Refcount) Release() {
3031
}
3132
r.Buffers = nil
3233
r.Dependencies = nil
33-
if r.Additional != nil {
34-
r.Additional()
34+
for _, derived := range r.Derived {
35+
*((*uintptr)(derived)) = 0
3536
}
3637
} else if new < 0 {
3738
// This branch can be optimized out when !debug

0 commit comments

Comments
 (0)