<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hi Michael!<br>
<br>
Thanks for trying out the FFM API.</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
I am a bit uncertain as to which versions are used in the various examples you show.<br>
<br>
In your first example, you must apply a "reinterpret" operation on the ptr because MemorySegment::ofAddress returns a MemorySegment of size zero. Presumably, the ptr is (at least) of size ValueLayout.ADDRESS.byteSize().<br>
<br>
"Unsafe" in the context of MemorySegment operations means bypassing normal Java safety guarantees and, for example, creating a reference that points to arbitrary memory locations that, in turn, could crash the JVM or produce unpredictable results. <br>
<br>
Thread safety, on the other hand, is another concept that means no sequence of valid operations can put an object in an illegal state, regardless of which thread operations were invoked. <br>
<br>
In other words, you can use a MemorySegment from any number of threads (if allocated from an arena that is not confined). When you are using "unsafe" operations like reinterpret, you need to be careful and make sure you provide the right parameters or the result
is unspecified.<br>
<br>
Best, Per Minborg</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> panama-dev <panama-dev-retn@openjdk.org> on behalf of Michael Hall <mik3hall@gmail.com><br>
<b>Sent:</b> Saturday, December 30, 2023 4:10 AM<br>
<b>To:</b> panama-dev@openjdk.org <panama-dev@openjdk.org><br>
<b>Subject:</b> MemorySegment javadoc (MacOS)</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Having a new arm Mac I am updating some of what I have to build on that.<br>
<br>
This no longer worked.<br>
<br>
MemorySegment flagsArray = MemorySegment.ofAddress(eventFlagsPtr,<br>
paths.length * SIZEOF_FS_EVENT_STREAM_EVENT_FLAGS);<br>
<br>
Looking at the MemorySegment documentation<br>
<br>
MemorySegment foreign = someSegment.get(ValueLayout.ADDRESS, 0); // size = 0<br>
.reinterpret(4) // size = 4<br>
<br>
(Nit: the semicolon is misplaced)<br>
<br>
I thought I should have something like<br>
<br>
MemorySegment ptr = MemorySegment.ofAddress(eventFlagsPtr);<br>
MemorySegment flagsArray = ptr.get(ValueLayout.ADDRESS, 0).<br>
.reinterpret(paths.length * SIZEOF_FS_EVENT_STREAM_EVENT_FLAGS);<br>
<br>
This didn’t work with an index out of bounds exception. Which seemed awkward but should of worked?<br>
<br>
I went with the more straight forward <br>
<br>
MemorySegment flagsArray = MemorySegment.ofAddress(eventFlagsPtr).<br>
reinterpret(paths.length * SIZEOF_FS_EVENT_STREAM_EVENT_FLAGS);<br>
<br>
…which worked. If this is considered a more straightforward jdk21 way of doing the above jdk20 code should it be in the javadoc?<br>
<br>
Also I find a little confusing where it indicates <br>
<br>
clients have several options, all of which are unsafe.<br>
<br>
But then at the end has…<br>
<br>
Implementation Requirements:<br>
Implementations of this interface are immutable, thread-safe and value-based.<br>
<br>
Is it safe or unsafe? Unsafe in the sense that the size could be incorrect?<br>
<br>
Thanks,<br>
<br>
Mike</div>
</span></font></div>
</body>
</html>