Reading binary data

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Oct 30 21:22:26 UTC 2019


On 30/10/2019 20:06, Ty Young wrote:
>
> On 10/30/19 9:56 AM, Maurizio Cimadamore wrote:
>>
>> On 30/10/2019 13:47, Ty Young wrote:
>>> I've stumbled across a function that returns a pointer to memory 
>>> which contains data(AKA binary data) and a size for it. I'm 
>>> assuming(correct me if I'm wrong here) that accessing this data 
>>> requires use of lower level foreign memory API however the API seems 
>>> to have changed since the presentation given a few months back. What 
>>> is the correct way currently for accessing this data?
>>>
>>>
>>>
>> Hi,
>> I don't think the API has changed much - here's the javadoc (since 
>> then we added support for mapped segments and for concurrency, but 
>> the bulk of the API is the same).
>>
>> http://cr.openjdk.java.net/~mcimadamore/panama/memaccess_javadoc/
>
>
> Seems like the build i'm using doesn't have the lower level memory 
> access API. I'm using the 2019 JDK build. Are there pre-built JDKs 
> available or is compiling from source required?
At the moment we don't have prebuilt binaries with the low level API.
>
>
>>
>> To help you with your use case I'd need first to understand how you 
>> are going to call that function - is it a native function (I assume)? 
>> Are you calling such function using the Panama foreign API, or the 
>> stuff in foreign-abi?
>
>
> Yes, native. Just using foreign Pointer API.

Well, if you are using the Pointer API, you could in principle read 
binary data with that too?

E.g. you can cast a Pointer<?> to a pointer of the right type using the 
cast() method and then work it from here - e.g.

Pointer<?> buffer = ...
Pointer<Integer> intPointer = buffer.cast(NativeTypes.INT);
for (int i = 0 ; i < size ; i++) {
    int x = intPointer.offset(i).get();
}

Maurizio

>
>
>>
>> Maurizio
>>
>>


More information about the panama-dev mailing list