CurtHagenlocher commented on code in PR #291:
URL: https://github.com/apache/arrow-dotnet/pull/291#discussion_r2971872218
##########
src/Apache.Arrow/Arrays/ArrayData.cs:
##########
@@ -97,8 +101,57 @@ public ArrayData(
Dictionary = dictionary;
}
+ private ArrayData(
+ ArrayData parent,
+ IArrowType dataType,
+ int length, int nullCount, int offset,
+ ArrowBuffer[] buffers, ArrayData[] children, ArrayData dictionary)
+ {
+ _parent = parent;
+ DataType = dataType ?? NullType.Default;
+ Length = length;
+ NullCount = nullCount;
+ Offset = offset;
+ Buffers = buffers;
+ Children = children;
+ Dictionary = dictionary;
+ }
+
+ /// <summary>
+ /// Increment the reference count, allowing this ArrayData to be shared
+ /// across multiple owners. Each call to Acquire must be balanced by a
+ /// call to <see cref="Dispose"/>.
+ /// </summary>
+ /// <returns>This instance.</returns>
+ public ArrayData Acquire()
+ {
+ if (Interlocked.Increment(ref _referenceCount) <= 1)
+ {
+ Interlocked.Decrement(ref _referenceCount);
+ throw new ObjectDisposedException(nameof(ArrayData));
+ }
+ return this;
+ }
+
public void Dispose()
{
+ int remaining = Interlocked.Decrement(ref _referenceCount);
+ if (remaining > 0)
+ {
+ return;
+ }
+ if (remaining < 0)
+ {
+ throw new ObjectDisposedException(nameof(ArrayData),
"ArrayData has already been disposed.");
Review Comment:
I'm sympathetic to this, but I can't find a way to make this work any better
without breaking backwards compatibility.
--
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]