[foreign-memaccess+abi] RFR: 8264933: Improve stream support in memory segments
Rémi Forax
github.com+828220+forax at openjdk.java.net
Fri Apr 9 16:46:25 UTC 2021
On Fri, 9 Apr 2021 13:45:53 GMT, Maurizio Cimadamore <mcimadamore 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 ;-) )
>
> Proposal: instead of what we do in this PR, let's tweak things a little:
>
> * for usability, let's add `MemorySegment::slices(MemoryLayout)`, which returns a _sequential_ stream of all the slices in a segment (with given element layout).
> * for advanced use cases, including parallel streams, users will have to use spliterator + StreamSupport, as before.
>
> This doesn't close the door to other stream-ified views to be added in the future. What do people think?
I don't see the point of slicing a segment into slice of one element.
Can we have a second argument with the maximum size of a sub-segment ?
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/494
More information about the panama-dev
mailing list