Pointer implements Closeable { @Nonnull public static Pointer<Void> malloc(@Nonnegative final int size) { if (size < 0) { throw new IllegalArgumentException("Given size argument is not a positive number."); } final long address = JNI.malloc(size); if (ENABLE_LOG) { Logger.getLogger("jaccall") .log(Level.FINE, "Heap allocated memory at address=0x" + String.format("%016X", address)); } return wrap(address); } Pointer(@Nonnull final Type type,
            final long address,
            final boolean autoFree,
            final int typeSize); @Nonnull static Pointer<Void> wrap(@Nonnull final ByteBuffer byteBuffer); @Nonnull static Pointer<U> wrap(@Nonnull final Class<U> type,
                                      @Nonnull final ByteBuffer byteBuffer); @Nonnull static Pointer<Void> wrap(final long address); @Nonnull static Pointer<U> wrap(@Nonnull final Class<U> type,
                                      final long address); static Pointer<Void> realloc(@Nonnull Pointer<?> pointer,
                                        @Nonnegative final int size); static Pointer<U> realloc(@Nonnull Pointer<?> pointer,
                                         @Nonnegative final int size,
                                         @Nonnull final Class<U> type); @Nonnull static Pointer<Void> malloc(@Nonnegative final int size); @Nonnull static Pointer<U> malloc(@Nonnegative final int size,
                                        @Nonnull final Class<U> type); @Nonnull static Pointer<Void> calloc(@Nonnegative final int nmemb,
                                       @Nonnegative final int size); @Nonnull static Pointer<U> calloc(@Nonnegative final int nmemb,
                                        @Nonnegative final int size,
                                        @Nonnull final Class<U> type); @Nonnull static Pointer<CLong> nref(@Nonnull final CLong... val); static Pointer<Object> from(@Nonnull final Object val); @Nonnull static Pointer<U> ref(@Nonnull final U val); @SafeVarargs @Nonnull static Pointer<U> nref(@Nonnull final U... val); @SafeVarargs @Nonnull static Pointer<U> nref(@Nonnull final U... val); @Nonnull static Pointer<Byte> nref(@Nonnull final byte... val); @Nonnull static Pointer<Short> nref(@Nonnull final short... val); @Nonnull static Pointer<Integer> nref(@Nonnull final int... val); @Nonnull static Pointer<Float> nref(@Nonnull final float... val); @Nonnull static Pointer<Long> nref(@Nonnull final long... val); @Nonnull static Pointer<Double> nref(@Nonnull final double... val); @Nonnull static Pointer<String> nref(@Nonnull final String val); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); void close(); @Nonnull abstract T get(); @Nonnull abstract T get(@Nonnegative final int index); @Nonnull final Pointer<T> inc(); @Nonnull final Pointer<T> dec(); @Nonnull final Pointer<T> plus(final int value); @Nonnull final Pointer<T> minus(final int value); @Nonnull Pointer<U> castp(@Nonnull final Class<U> type); @Nonnull Pointer<Pointer<T>> castpp(); abstract void set(@Nonnull final T val); abstract void set(@Nonnegative final int index,
                             @Nonnull final T val); final long address; }
@Test public void testMalloc() throws Exception { final int cLongSize = sizeof((CLong) null); final CLong cLong = new CLong(123456); try (final Pointer<CLong> cLongPointer = malloc(cLongSize).castp(CLong.class);) { cLongPointer.set(cLong); final long nativeCLongRead = JNITestUtil.getCLong(cLongPointer.address); assertThat(nativeCLongRead).isEqualTo(cLong.longValue()); } }