zhztheplayer commented on code in PR #34231:
URL: https://github.com/apache/arrow/pull/34231#discussion_r1111404207
##########
java/memory/memory-core/src/main/java/org/apache/arrow/memory/BaseAllocator.java:
##########
@@ -233,6 +233,41 @@ private void childClosed(final BaseAllocator
childAllocator) {
listener.onChildRemoved(this, childAllocator);
}
+ @Override
+ public ArrowBuf wrapForeignAllocation(ForeignAllocation allocation) {
+ assertOpen();
+ final long size = allocation.getSize();
+ listener.onPreAllocation(size);
+ AllocationOutcome outcome = this.allocateBytes(size);
+ if (!outcome.isOk()) {
+ if (listener.onFailedAllocation(size, outcome)) {
+ // Second try, in case the listener can do something about it
+ outcome = this.allocateBytes(size);
+ }
+ if (!outcome.isOk()) {
+ throw new OutOfMemoryException(createErrorMsg(this, size,
+ size), outcome.getDetails());
+ }
+ }
+ try {
+ final AllocationManager manager = new ForeignAllocationManager(this,
allocation);
+ final BufferLedger ledger = manager.associate(this);
+ final ArrowBuf buf =
+ new ArrowBuf(ledger, /*bufferManager=*/null, size,
allocation.memoryAddress());
+ buf.writerIndex(size);
+ listener.onAllocation(size);
+ return buf;
+ } catch (Throwable t) {
+ try {
+ releaseBytes(size);
+ allocation.release0();
Review Comment:
Thanks but would you give some hints on this? Or would you suggest adding a
local variable `Throwable xx` to save the error for further handling?
--
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]