Pointer/Scope API questions
Ty Young
youngty1997 at gmail.com
Tue Jan 7 13:47:45 UTC 2020
On 12/22/19 3:10 PM, Maurizio Cimadamore wrote:
>
> On 21/12/2019 23:59, Ty Young wrote:
>> Hi,
>>
>>
>> There are a few questions I'd like to ask after using it for awhile:
>>
>>
>> A. the implementation of equals on Pointers and Scopes... How is it
>> implemented? In the case of Pointers, does the scope of which the
>> pointer was allocated matter? Is comparing Pointers to a struct of a
>> given type as reliable as comparing the structs themselves?
> Pointer equality just compares the addresses - not the scopes; that
> is, if two pointers p1 and p2 point to the same memory location, they
> are considered equals.
Is there no way to fix this?
> As to your question about differences w/r/t struct comparison, I don't
> think the API support struct comparison.
Regardless of whether the API supports it or not, equals is apart of
every Object. Maybe an unchecked exception should be thrown?
>>
>>
>> B. Is mixing allocated native types from different scopes and using
>> them together safe? Will it result in any weird side affects?
>
> You can allocate pointers from different scopes and mix them. The
> general rule of thumb (described here [1]) is that you can only write
> a pointer p1 into a memory pointed by p2 if p1 is guaranteed to
> outlive p2.
Thanks for the clarification.
>
>
>>
>>
>> C. What scope are Pointers from C from exactly? The libraries
>> specific scope? Are there exceptions like If a function returns a
>> Pointer which is derived from function argument Pointer data, is the
>> scope the same as the input arguments?
>
> Pointers that come from C have the 'unchecked' scope - as such they
> are 'unmanaged' pointers. As such you can do whatever you like with
> them, as the Panama/foreign branch doesn't restrict use of native
> pointers in any way - which also means that it's not easy to make them
> safer also (e.g. if you happen to know more about the native pointer
> bounds). All the work in the Pointer API predates some of the
> discussions on how to make native pointer safer, which we had more
> recently.
So once Pointer is rebased on the memory access API, you'll be able to
get the underlying MemoryAddress from it and do with it as you will?
>
> Maurizio
>
> [1] - http://cr.openjdk.java.net/~mcimadamore/panama/scopes.html
>
>>
>>
>> Thanks for any clarity.
>>
More information about the panama-dev
mailing list