jcuda
Class Pointer

java.lang.Object
  extended by jcuda.NativePointerObject
      extended by jcuda.Pointer
Direct Known Subclasses:
CUdeviceptr

public class Pointer
extends NativePointerObject

A Java representation of a void pointer.


Constructor Summary
Pointer()
          Creates a new (null) Pointer
 
Method Summary
 java.nio.ByteBuffer getByteBuffer(long byteOffset, long byteSize)
          Returns a ByteBuffer that corresponds to the specified segment of the memory that this pointer points to.
static Pointer to(java.nio.Buffer buffer)
          NOTE: This method does not take into account the position and array offset of the given buffer.
static Pointer to(byte[] values)
          Creates a new Pointer to the given values.
static Pointer to(char[] values)
          Creates a new Pointer to the given values.
static Pointer to(double[] values)
          Creates a new Pointer to the given values.
static Pointer to(float[] values)
          Creates a new Pointer to the given values.
static Pointer to(int[] values)
          Creates a new Pointer to the given values.
static Pointer to(long[] values)
          Creates a new Pointer to the given values.
static Pointer to(NativePointerObject... pointers)
          Creates a new Pointer to the given Pointers.
static Pointer to(short[] values)
          Creates a new Pointer to the given values.
static Pointer toBuffer(java.nio.Buffer buffer)
          Creates a new Pointer to the given buffer.
 java.lang.String toString()
          Returns a String representation of this object.
 Pointer withByteOffset(long byteOffset)
          Returns a new pointer with an offset of the given number of bytes
 
Methods inherited from class jcuda.NativePointerObject
equals, hashCode
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pointer

public Pointer()
Creates a new (null) Pointer

Method Detail

to

public static Pointer to(byte[] values)
Creates a new Pointer to the given values.

Parameters:
values - The values the pointer should point to
Returns:
The pointer

to

public static Pointer to(char[] values)
Creates a new Pointer to the given values. The values may not be null.

Parameters:
values - The values the pointer should point to
Returns:
The pointer

to

public static Pointer to(short[] values)
Creates a new Pointer to the given values. The values may not be null.

Parameters:
values - The values the pointer should point to
Returns:
The pointer

to

public static Pointer to(int[] values)
Creates a new Pointer to the given values. The values may not be null.

Parameters:
values - The values the pointer should point to
Returns:
The pointer

to

public static Pointer to(float[] values)
Creates a new Pointer to the given values. The values may not be null.

Parameters:
values - The values the pointer should point to
Returns:
The pointer

to

public static Pointer to(long[] values)
Creates a new Pointer to the given values. The values may not be null.

Parameters:
values - The values the pointer should point to
Returns:
The pointer

to

public static Pointer to(double[] values)
Creates a new Pointer to the given values. The values may not be null.

Parameters:
values - The values the pointer should point to
Returns:
The pointer

to

public static Pointer to(java.nio.Buffer buffer)
NOTE: This method does not take into account the position and array offset of the given buffer. In order to create a pointer that takes the position and array offset into account, use the toBuffer(Buffer) method.

If the given buffer has a backing array, then the returned pointer will in any case point to the start of the array, even if the buffer has been created using the slice method (like ByteBuffer.slice()). If the buffer is direct, then this method will return a Pointer to the address of the direct buffer. If the buffer has been created using the slice method, then this will be the actual start of the slice. Although this implies a different treatment of direct- and non direct buffers, the method is kept for backward compatibility.

In both cases, for direct and array-based buffers, this method does not take into account the position of the given buffer.

The buffer must not be null, and either be a direct buffer, or have a backing array

Parameters:
buffer - The buffer the pointer should point to
Returns:
The pointer
Throws:
java.lang.IllegalArgumentException - If the given buffer is null or is neither direct nor has a backing array

toBuffer

public static Pointer toBuffer(java.nio.Buffer buffer)
Creates a new Pointer to the given buffer.

Note that this method takes into account the array offset and position of the given buffer, in contrast to the to(Buffer) method.

Parameters:
buffer - The buffer
Returns:
The new pointer
Throws:
java.lang.IllegalArgumentException - If the given buffer is null or is neither direct nor has a backing array

to

public static Pointer to(NativePointerObject... pointers)
Creates a new Pointer to the given Pointers. The array of pointers may not be null, and may not contain null elements.

Parameters:
pointers - The pointers the pointer should point to
Returns:
The new pointer
Throws:
java.lang.IllegalArgumentException - If the given array is null

withByteOffset

public Pointer withByteOffset(long byteOffset)
Returns a new pointer with an offset of the given number of bytes

Parameters:
byteOffset - The byte offset for the pointer
Returns:
The new pointer with the given byte offset

getByteBuffer

public java.nio.ByteBuffer getByteBuffer(long byteOffset,
                                         long byteSize)
Returns a ByteBuffer that corresponds to the specified segment of the memory that this pointer points to.

This function may only be applied to pointers that have been set to point to a region of host memory using either of the methods JCudaDriver.cuMemAllocHost(Pointer, long), JCudaDriver.cuMemHostAlloc(Pointer, long, int), JCuda.cudaMallocHost(Pointer, long) or JCuda.cudaHostAlloc(Pointer, long, int), or pointers that have been created with to(byte[]).

For other pointer types, null is returned.

Parameters:
byteOffset - The offset in bytes
byteSize - The size of the byte buffer, in bytes
Returns:
The byte buffer

toString

public java.lang.String toString()
Returns a String representation of this object.

Overrides:
toString in class NativePointerObject
Returns:
A String representation of this object.