adamreeve commented on code in PR #297:
URL: https://github.com/apache/arrow-dotnet/pull/297#discussion_r3007363833


##########
src/Apache.Arrow/ChunkedArray.cs:
##########
@@ -39,11 +40,21 @@ public int ArrayCount
         public IArrowArray ArrowArray(int index) => Arrays[index];
 
         public ChunkedArray(IList<Array> arrays)
-            : this(Cast(arrays))
+            : this(Cast(arrays), disposeArrays: false)

Review Comment:
   Is this now needed with the ref counted buffers but it wasn't needed before 
with ref counted ArrayData? Or should the ArrayData approach also have also 
defaulted to not disposing the child arrays?



##########
src/Apache.Arrow/Memory/SharedMemoryOwner.cs:
##########
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using System.Buffers;
+using System.Threading;
+
+namespace Apache.Arrow.Memory
+{
+    internal sealed class SharedMemoryOwner
+    {
+        private readonly IMemoryOwner<byte> _inner;
+        private readonly Memory<byte> _memory;
+        private int _refCount;
+
+        public SharedMemoryOwner(IMemoryOwner<byte> inner)
+        {
+            _inner = inner ?? throw new ArgumentNullException(nameof(inner));
+            _memory = inner.Memory;
+            _refCount = 1;
+        }
+
+        public Memory<byte> Memory => _memory;
+
+        public SharedMemoryHandle Retain()
+        {
+            while (true)
+            {
+                int current = Volatile.Read(ref _refCount);
+                if (current <= 0)
+                {
+                    throw new 
ObjectDisposedException(nameof(SharedMemoryOwner));
+                }
+
+                if (Interlocked.CompareExchange(ref _refCount, current + 1, 
current) == current)
+                {
+                    return new SharedMemoryHandle(this);
+                }
+            }
+        }
+
+        public void Release()
+        {
+            if (Interlocked.Decrement(ref _refCount) == 0)
+            {
+                _inner.Dispose();
+            }
+        }
+
+        public T GetInner<T>() where T : class

Review Comment:
   This looks unused, should it be removed?



##########
src/Apache.Arrow/Memory/SharedMemoryHandle.cs:
##########
@@ -14,11 +14,30 @@
 // limitations under the License.
 
 using System;
+using System.Buffers;
 
 namespace Apache.Arrow.Memory
 {
-    internal interface IOwnableAllocation
+    internal sealed class SharedMemoryHandle : IMemoryOwner<byte>
     {
-        bool TryAcquire(out IntPtr ptr, out int offset, out int length);
+        private SharedMemoryOwner _owner;
+
+        public SharedMemoryHandle(SharedMemoryOwner owner)
+        {
+            _owner = owner ?? throw new ArgumentNullException(nameof(owner));
+        }
+
+        public Memory<byte> Memory => _owner.Memory;
+
+        public SharedMemoryHandle Retain()
+        {
+            return _owner.Retain();
+        }
+
+        public void Dispose()

Review Comment:
   Should this also have a finalizer to handle when this is garbage collected 
without being disposed?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to