[foreign] RFR : Move array-like methods from Pointer to Array

Jorn Vernee jbvernee at xs4all.nl
Mon Nov 19 13:34:09 UTC 2018


> The reason I don't like the current approach of elements() is that the
> returned stream is essentially infinite, but it creates the false
> illusion that if you have a pointer to some native array (not obtained
> through Array::elementPointer, which is sized explicitly) that this
> stream will contain only the elements of that array, while in reality
> it will just keep iterating beyond that if the BoundedMemoryRegion is
> larger (which it _always_ is for arrays allocated on the native side).

Acutally, I realized this statement is based on the old 
BoundedMemoryRegion code (which I recently changed). Currently, the 
elements() method will just throw an UOE when calling it on a 
native-allocated pointer, because the underlying BoundedMemoryRegion has 
no explicit length. Meaning you can only iterate over pointers allocated 
from the Java side, which are all probably coming from 
`Array::elementPointer` any ways, so that's not a problem.

Creating a Stream manually using Stream::iterate and Pointer::offset 
still works for both though.

Sorry about that,
Jorn


More information about the panama-dev mailing list