You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/09/27 21:01:50 UTC

[GitHub] [arrow] lidavidm commented on a diff in pull request #13248: ARROW-16673: [Java] C data interface: Allow ownership transferring for imported buffer

lidavidm commented on code in PR #13248:
URL: https://github.com/apache/arrow/pull/13248#discussion_r981711344


##########
java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java:
##########
@@ -704,6 +705,37 @@ public void testImportReleasedArray() {
     }
   }
 
+  @Test
+  public void testTransferImportedBuffer() {
+    VectorSchemaRoot imported;
+
+    // Consumer allocates empty structures
+    try (ArrowSchema consumerArrowSchema = ArrowSchema.allocateNew(allocator);
+        ArrowArray consumerArrowArray = ArrowArray.allocateNew(allocator)) {
+      try (VectorSchemaRoot vsr = createTestVSR()) {
+        // Producer creates structures from existing memory pointers
+        try (ArrowSchema arrowSchema = ArrowSchema.wrap(consumerArrowSchema.memoryAddress());
+            ArrowArray arrowArray = ArrowArray.wrap(consumerArrowArray.memoryAddress())) {
+          // Producer exports vector into the C Data Interface structures
+          Data.exportVectorSchemaRoot(allocator, vsr, null, arrowArray, arrowSchema);
+        }
+      }
+      // Consumer imports vector
+      imported = Data.importVectorSchemaRoot(allocator, consumerArrowArray, consumerArrowSchema, null);
+    }
+
+    try (BufferAllocator targetAllocator = allocator.newChildAllocator("transfer allocator", 0, Long.MAX_VALUE)) {
+      for (FieldVector fieldVector : imported.getFieldVectors()) {
+        int cnt = fieldVector.getValueCount();
+        // Transfer buffer ownerships. Should not report any error
+        TransferPair transferPair = fieldVector.getTransferPair(targetAllocator);
+        transferPair.transfer();
+        ValueVector to = transferPair.getTo();
+        assertEquals(cnt, to.getValueCount());

Review Comment:
   What does targetAllocator report for allocated bytes after the transfer?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org