Visibility & Scope understanding.

Jorn Vernee jbvernee at xs4all.nl
Tue Jun 4 09:48:27 UTC 2019


Hi Giorgio,

> in the constructor i have inside a scope:

I assume you mean a try-with-resources block here? If you want the 
resource to outlive your constructor just don't use try-with-resources. 
You can open a scope and add a close() method to the class to close the 
scope again. e.g.:

     class Widget {
         private final Pointer<Pointer<botan_mac_struct>> botanMac;

         public Widget() {
             // using library scope here, could also use 
`Scope.globalScope().fork()`
             this.botanMac = 
scope().allocate(LayoutType.ofStruct(botan_mac_struct.class).pointer());
         }

         public void close() {
             botanMac.scope().close();
         }
     }

Jorn

Giorgio Zoppi schreef op 2019-06-01 18:32:
> Dear all,
> your panama tool is excellent. I need a deeper understanding on how to 
> use
> an opaque object for my botan java binding (botan is a C++ 
> cryptolibrary)
> 
> Basically my code has an opaque pointer
> :
> private Pointer<Pointer<botan_mac_struct>> botanMac;
> 
> in the constructor i have inside a scope:
> 
>  this.botanMac =
> scope().allocate(LayoutType.ofStruct(botan_mac_struct.class).pointer());
> 
> How can I have class scope? The botanMac object will be used everywhere
> inside the class and not just in the ctor. Do you have any docs about 
> that?
> Best Regards,
> Giorgio


More information about the panama-dev mailing list