<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <div class="markdown-here-wrapper" data-md-url="" style="">
      <p style="margin: 0px 0px 1.2em !important;">Some additional
        notes, as we dug into this more.</p>
      <p style="margin: 0px 0px 1.2em !important;">The main issue you
        describe is this:</p>
      <blockquote style="margin: 1.2em 0px;border-left: 4px solid rgb(221, 221, 221); padding: 0px 1em; color: rgb(119, 119, 119); quotes: none;">
        <blockquote style="margin: 1.2em 0px;border-left: 4px solid rgb(221, 221, 221); padding: 0px 1em; color: rgb(119, 119, 119); quotes: none;">
          <blockquote style="margin: 1.2em 0px;border-left: 4px solid rgb(221, 221, 221); padding: 0px 1em; color: rgb(119, 119, 119); quotes: none;">
            <p style="margin: 0px 0px 1.2em !important;">What makes this
              worse is that if you are just given a<br>
              SymbolLookup, or even a MemorySegment obtained from it,
              you don’t<br>
              have access to the original Arena used to load the
              library, so<br>
              you cannot even manually fix this unsafety this by using<br>
              <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;">MemorySegment#reinterpet</code>
              to change the Arena.</p>
            <p style="margin: 0px 0px 1.2em !important;">A similar
              problem to the one you cite was mentioned in this document
              we shared a while ago:</p>
          </blockquote>
        </blockquote>
      </blockquote>
      <p style="margin: 0px 0px 1.2em !important;"><a href="https://cr.openjdk.org/~mcimadamore/panama/scoped_arenas.html" class="moz-txt-link-freetext">https://cr.openjdk.org/~mcimadamore/panama/scoped_arenas.html</a></p>
      <p style="margin: 0px 0px 1.2em !important;">See section on
        “co-allocation”.</p>
      <p style="margin: 0px 0px 1.2em !important;">At the time we
        concluded (based on feedback) that the usefulness of the
        proposed factory to “convert” a scope back into an Arena was
        limited. As such we decided to leave that out. That is, even if
        we could see that there were cases where a client might expect
        to e.g. be able to allocate a new segment with the same lifetime
        of an existing segment, the cases where this came up seemed
        rather obscure, and even then, it wasn’t clear as to whether it
        was something that was 100% ok for the client to be wanting to
        do.</p>
      <p style="margin: 0px 0px 1.2em !important;">You seem to have use
        case where you need to perform a reinterpret - but have no
        Arena. Can you please share more about your use case? E.g. are
        you really in a situation where you don’t have an Arena, or are
        you concerned about a case where you <em>might</em> not have
        one?</p>
      <p style="margin: 0px 0px 1.2em !important;">For instance, in the
        case you mention there is a native library. This is loaded using
        a SymbolLookup - probably SymbolLookup::libraryLookup. This
        lookup takes an Arena. If you are using jextract, jextract will
        emit a constant called <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px; display: inline;">LIBRARY_ARENA</code>
        which will give you the arena used by jextract to generate the
        bindings (although, I see that constant is currently
        package-private, so probably not accessible). So, at least in
        the common case of jextract-generated code, something along the
        lines of what you want to do seems already possible.</p>
      <p style="margin: 0px 0px 1.2em !important;">If you did not use
        jextract, but created your own bindings manually, the same
        approach could in principle be replicated: there’s an arena for
        the entire library - and you can access it in order to allocate,
        reinterpret, etc. Is there a specific reason as to why you think
        this approach is not viable in your case? If so, we’re genuinely
        interested in knowing more about your code.</p>
      <p style="margin: 0px 0px 1.2em !important;">Cheers<br>
        Maurizio</p>
      <div title="MDH:U29tZSBhZGRpdGlvbmFsIG5vdGVzLCBhcyB3ZSBkdWcgaW50byB0aGlzIG1vcmUuPGJyPjxicj5U
aGUgbWFpbiBpc3N1ZSB5b3UgZGVzY3JpYmUgaXMgdGhpczo8YnI+PGJyPjxzcGFuIHN0eWxlPSJ3
aGl0ZS1zcGFjZTogcHJlLXdyYXA7IGRpc3BsYXk6IGJsb2NrOyB3aWR0aDogOTh2dzsiPiZndDsm
Z3Q7Jmd0OyA8YnI+Jmd0OyZndDsmZ3Q7IFdoYXQgbWFrZXMgdGhpcyB3b3JzZSBpcyB0a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:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0;">​</div>
    </div>
  </body>
</html>