jnr.ffi
Class Memory

java.lang.Object
  extended by jnr.ffi.Memory

public final class Memory
extends Object

A utility for allocating memory that can be passed to native functions.


Method Summary
static Pointer allocate(Runtime runtime, int size)
          Allocates a new block of java memory and wraps it in a Pointer accessor.
static Pointer allocate(Runtime runtime, NativeType type)
          Allocates a new block of java memory and wraps it in a Pointer accessor.
static Pointer allocateDirect(Runtime runtime, int size)
          Allocates a new block of native memory and wraps it in a Pointer accessor.
static Pointer allocateDirect(Runtime runtime, int size, boolean clear)
          Allocates a new block of native memory and wraps it in a Pointer accessor.
static Pointer allocateDirect(Runtime runtime, NativeType type)
          Allocates a new block of native memory and wraps it in a Pointer accessor.
static Pointer allocateTemporary(Runtime runtime, NativeType type)
          Allocates a new block of transient native memory and wraps it in a Pointer accessor.
static Pointer allocateTemporary(Runtime runtime, NativeType type, boolean clear)
          Allocates a new block of transient native memory and wraps it in a Pointer accessor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

allocate

public static final Pointer allocate(Runtime runtime,
                                     int size)
Allocates a new block of java memory and wraps it in a Pointer accessor.

Parameters:
size - The size in bytes of memory to allocate.
Returns:
a Pointer instance that can access the memory.

allocate

public static final Pointer allocate(Runtime runtime,
                                     NativeType type)
Allocates a new block of java memory and wraps it in a Pointer accessor.

Parameters:
type - The native type to allocate memory for.
Returns:
a Pointer instance that can access the memory.

allocateDirect

public static final Pointer allocateDirect(Runtime runtime,
                                           int size)
Allocates a new block of native memory and wraps it in a Pointer accessor.

Parameters:
size - The size in bytes of memory to allocate.
Returns:
a Pointer instance that can access the memory.

allocateDirect

public static final Pointer allocateDirect(Runtime runtime,
                                           NativeType type)
Allocates a new block of native memory and wraps it in a Pointer accessor.

Parameters:
type - The native type to allocate memory for.
Returns:
a Pointer instance that can access the memory.

allocateDirect

public static final Pointer allocateDirect(Runtime runtime,
                                           int size,
                                           boolean clear)
Allocates a new block of native memory and wraps it in a Pointer accessor.

Parameters:
size - The size in bytes of memory to allocate.
clear - Whether the memory contents should be cleared, or left as random data.
Returns:
a Pointer instance that can access the memory.

allocateTemporary

public static final Pointer allocateTemporary(Runtime runtime,
                                              NativeType type)
Allocates a new block of transient native memory and wraps it in a Pointer accessor. The memory returned by this method should not be passed to native methods that store the address for later use, as it may change each time it is passed to native code.

Parameters:
type - The native type to allocate memory for.
Returns:
a Pointer instance that can access the memory.

allocateTemporary

public static final Pointer allocateTemporary(Runtime runtime,
                                              NativeType type,
                                              boolean clear)
Allocates a new block of transient native memory and wraps it in a Pointer accessor. The memory returned by this method should not be passed to native methods that store the address for later use, as it may change each time it is passed to native code.

Parameters:
type - The native type to allocate memory for.
clear - Whether the memory contents should be cleared, or left as random data.
Returns:
a Pointer instance that can access the memory.


Copyright © 2012. All Rights Reserved.