[foreign-memaccess+abi] RFR: 8264933: Improve stream support in memory segments

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri Apr 9 13:33:26 UTC 2021


On Fri, 9 Apr 2021 13:01:58 GMT, Rémi Forax <github.com+828220+forax at openjdk.org> wrote:

> This is true when using VarHandle too, as a user you have to use the right segment.

Yes! Which is why having a memory segment slice that give you access only to the portion of data you want is the right way to approach this:

segment.addresses(AN_INT)
       .mapToInt(MemoryAccess::getInt)
       .sum();

I don't question that, in some cases, having a stream of offsets would be handy - but the goal of this PR is mostly to avoid what the API forces you to do today: `StreamSupport.stream(segment.spliterator(LAYOUT), true/false)`. Surely we can add other accessors in the future?

Is it possible we are quibbling over naming? E.g. perhaps instead of calling this new method `MemorySegment::stream` and suggesting that this is _the way_ to view a segment as a stream, perhaps calling it "slices" would be more honest? I'm open to that, although that needs some way to create a parallel stream too (`MemorySegment::slices` looks good, `MemorySegment::asParallelSlices` not so much ;-) )

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/494


More information about the panama-dev mailing list