<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>Hi,<br>
      the functionality is there - it has just been renamed to make it
      more general.</p>
    <p>In 20, one could only create an address layout that was
      _unbounded_ e.g. that pointed to a region of memory of unbounded
      size.</p>
    <p>In 21, AddressLayout is a new toplevel class. An address layout
      has a _target layout_ [1] which is used to describe the layout of
      the pointed region of memory.</p>
    <p>This means that you can still get a behavior similar to
      `asUnbounded`, by doing:<br>
      <br>
      ```java<br>
      ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(JAVA_BYTE))<br>
      ```</p>
    <p>The above will create a sequence layout of unbound size (so, the
      size of that layout would be Long.MAX_VALUE), and use that layout
      as the target for the address layout. Which means that when this
      address is passed to MemorySegment::get(AddressLayout), or to the
      Linker, you will get back a MemorySegment whose size is
      Long.MAX_VALUE (as in 21).<br>
    </p>
    <p>But, if you know the layout of the pointed region of memory
      statically, you can also use a sharper target layout - e.g.</p>
    <p>```java<br>
      ADDRESS.withTargetLayout(JAVA_INT)<br>
      ```</p>
    <p>The latter will create an address layout whose target layout is
      _exactly_ one int layout. This means that when you pass this
      address layout to MemorySegment::get(AddressLayout),or to the
      Linker, you will get back a MemorySegment whose size is precisely
      4 bytes. This is especially useful for upcalls (as the qsort
      example in JEP 442 demonstrates).</p>
    <p>Hope this helps.<br>
    </p>
    <p>Maurizio<br>
    </p>
    <p>[1] -
<a class="moz-txt-link-freetext" href="https://cr.openjdk.org/~pminborg/panama/21/v2/javadoc/api/java.base/java/lang/foreign/AddressLayout.html#withTargetLayout(java.lang.foreign.MemoryLayout)">https://cr.openjdk.org/~pminborg/panama/21/v2/javadoc/api/java.base/java/lang/foreign/AddressLayout.html#withTargetLayout(java.lang.foreign.MemoryLayout)</a><br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 03/05/2023 14:34, Cheng Jin wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:BN8PR15MB257734849A4302232BA40403F56C9@BN8PR15MB2577.namprd15.prod.outlook.com">
      
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}div.WordSection1
        {page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hi there,<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I am wondering why
          asUnbounded()/isUnbounded() (existing in JDK20) related code
          was removed from
          java.base/share/classes/java/lang/foreign/ValueLayout.java in
          JDK21.<o:p></o:p></p>
        <p class="MsoNormal">Is there any reason for deleting them all
          (or moving them somewhere else which I ignored) for the
          unbounded segment (pointer)?<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Best Regards<o:p></o:p></p>
        <p class="MsoNormal">Cheng Jin<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
      </div>
    </blockquote>
  </body>
</html>