MemorySegment.close() is not idempotent

Remi Forax forax at univ-mlv.fr
Mon Mar 15 09:11:36 UTC 2021


To play with panama.foreign, i've partially re-implement the Apache Arrow [1] columnar format in pure Java.
So i've a bunch of dataset class that are wrappers of one or two MemorySegment (two if the data can be nullable) that represent a column of data.

I stumble on is the fact that a MemorySegment can not be closed more than once.
>From dataset, i can be wrapped to another one, think by example the unsigned int dataset being a wrapper on top on the signed one, but they share the same MemorySegment.

As a user i want to write something like
  try(var dataset = IntDataSet.from(MemorySegment.allocateMemory(5 * 4));
      var unsignedDataset = dataset.asUnsigned()) {
    ...
  }

the problem is that the MemorySegment.close() is not idempotent, so i've to check myself (with isAlive()) if the MemorySegment of a dataset has already been closed or not.

Did i miss something ?

regards,
RĂ©mi

[1] https://arrow.apache.org/docs/index.html


More information about the panama-dev mailing list