title: How to obtain a new Pointer in Java?
body: <p>How can I call a method with this method signature in C from JNA?</p>
  
  <pre><code>int open_device(context *ctx, device **dev, int index);
  </code></pre>
  
  <p>The last two lines of the C method look like this:</p>
  
  <pre><code>*dev = pdev;
  return 0;
  </code></pre>
  
  <p>That's the only use of <code>dev</code> in that method. That means that I have to pass a poiner to an empty pointer to the method, right? The method then fills the empty pointer with the address of a <code>device</code> object and I can pass the pointer to the device to other methods.</p>
  
  <p>My question is: Is this the right way to do that? If it is, how do I allocate a new pointer from Java?</p>
  
  <hr>
  
  <p>Based on the accepted answer, I did this:</p>
  
  <pre><code>Memory p = new Memory(Pointer.SIZE);
  Memory p2 = new Memory(Pointer.SIZE);
  p.setPointer(0, p2);
  nativeLib.open_device(ctx, p, index);
  return p2;
  </code></pre>