[foreign-memaccess+abi] RFR: 8264933: Improve stream support in memory segments
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Fri Apr 9 12:46:27 UTC 2021
On Fri, 9 Apr 2021 12:25:52 GMT, Rémi Forax <github.com+828220+forax at openjdk.org> wrote:
> So not using the "bulk" version leads to less performance but because it's a Stream of MemorySegment, you have to know as a user if you use the bulk version or not.
Yes
>
> I think i would prefer the stream to be a stream of the addresses,a LongStream instead of being a Stream of MemorySegment, so your last example can be written
>
> ```
> segment.addresses(C_POINTER)
> .map(CLinker::toJavaString)
> .toArray(String[]::new);
> ```
>
> Here, the element is just there to get its size.
>
> Having a stream of offsets/addresses will also work better with VarHandles, by example
>
> ```
> segment.addresses(AN_INT)
> .mapToInt(offset -> HANDLE.getInt(segment, offset))
> .sum();
> ```
I see what you mean: instead of returning slices, return offsets, and let the user deal with it. Honestly, I'm not sure - it seems like we are, again, prematurely concluding that slicing is gonna be more expensive, while the benchmarks I have show that the performance we get are the same as with Unsafe.
Note that we want each returned segment to be disjoint - an offset only tells me the starting point - doesn't tell me how big it is - which means it is possible/easier for clients to make mistake and write on "somebody else's" slice.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/494
More information about the panama-dev
mailing list