[foreign-memaccess] [Rev 01] RFR: Add MemorySegment::fill

Paul Sandoz psandoz at openjdk.java.net
Wed May 13 17:16:20 UTC 2020

On Wed, 13 May 2020 16:38:16 GMT, Chris Hegarty <chegar at openjdk.org> wrote:

>>> I think we need to consider grouping bulk operations in the same place.
>> I suggested the location to Chris. Since the method operates on segment it felt right to add it on MemorySegment. If we
>> add it on MemoryAddress it will look a tad odd IMHO, since it works on segments.
>> We could tweak fill to work on MemoryAddress, but that means that the user has to pass an address and a length (which
>> is what a segment is).
>> Or we could make fill an instance method on segment.
>> I'm not sure there's one answer that's better than the others here - but I don't have any strong feelings one way or
>> another, so I'm open to suggestions.
> I agree with the logic of why this method fits better in MemorySegment, rather than MemoryAddress.
> Fill seems more like a "utility", rather than an operation on the segment itself, so I marginally favour a static
> method.

I think `copy` is a little odd where it is located, for the same reasons argued if `fill` was located on
`MemoryAddress`, since both really operate on segments.

Using `MemoryAddress` affords some flexibility in terms of offset selection but that can also be achieved by slicing

As separate issues perhaps consider moving or duplicating `copy` on `MemorySegment` and exposing a `fill` accepting a
source segment?


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

More information about the panama-dev mailing list