本文整理汇总了Java中org.bridj.Pointer.set方法的典型用法代码示例。如果您正苦于以下问题:Java Pointer.set方法的具体用法?Java Pointer.set怎么用?Java Pointer.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bridj.Pointer
的用法示例。
在下文中一共展示了Pointer.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: indexOf
import org.bridj.Pointer; //导入方法依赖的package包/类
@Override
public int indexOf(Object o) {
Pointer<T> tmp = allocate(pointer.getIO());
tmp.set((T) o);
Pointer<T> occurrence = pointer.find(tmp);
if (occurrence == null) {
return -1;
}
return (int) (occurrence.getPeer() - pointer.getPeer());
}
示例2: lastIndexOf
import org.bridj.Pointer; //导入方法依赖的package包/类
@Override
public int lastIndexOf(Object o) {
Pointer<T> tmp = allocate(pointer.getIO());
tmp.set((T) o);
Pointer<T> occurrence = pointer.findLast(tmp);
if (occurrence == null) {
return -1;
}
return (int) (occurrence.getPeer() - pointer.getPeer());
}
示例3: controlTest
import org.bridj.Pointer; //导入方法依赖的package包/类
@Test
public void controlTest() {
Pointer<Byte> name = Pointer.pointerToCString("base");
Pointer<Byte> program = Pointer.pointerToCString(PROGRAM3);
clingo_part p = new clingo_part();
p.name(name);
p.params(null);
p.size(0);
Pointer<clingo_part> parts = Pointer.allocate(clingo_part.class);
parts.set(p);
Pointer<Integer> major = Pointer.allocateInt();
Pointer<Integer> minor = Pointer.allocateInt();
Pointer<Integer> revision = Pointer.allocateInt();
LIB.clingo_version(major, minor, revision);
System.out.println("Clingo library version: " + major.getInt() + "." + minor.getInt() + "." + revision.getInt());
// create a control object and pass command line arguments
Pointer<Pointer<clingo_control>> control = Pointer.allocatePointer(clingo_control.class);
if (!LIB.clingo_control_new(null, 0, null, null, 20, control)) {
error(control, "Could not create controller");
}
long startTime = System.currentTimeMillis();
// add a logic program to the base part
if (!LIB.clingo_control_add(control.get(), name, null, 0, program)) {
error(control, "Error add the program to controller");
}
// ground the base part
if (!LIB.clingo_control_ground(control.get(), parts, 1, null, null)) {
error(control, "Error ground the program");
}
if (!solve(control)) {
error(control, "Error solving the program");
}
float endTime = (System.currentTimeMillis() - startTime) / 1000f;
System.out.println("Time:" + String.format(TIME_FORMAT, endTime) + "s");
LIB.clingo_control_free(control.get());
}
示例4: main
import org.bridj.Pointer; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
CLContext context = JavaCL.createBestContext();
CLQueue clQueue = context.createDefaultQueue();
ByteOrder byteOrder = context.getByteOrder();
int n = 1024;
Pointer<Float> aPtr = allocateFloats(n).order(byteOrder);
for (int i = 0; i < n; i++) {
aPtr.set(i, (float)cos(i));
}
// Create OpenCL input/output buffers (using the native memory pointers aPtr and bPtr) :
CLBuffer<Float> a = context.createBuffer(Usage.InputOutput, aPtr);
// Read the program sources and compile them :
String src =
"__kernel void add_floats(global float* a, int n) {\n" +
" int i = get_global_id(0);\n" +
" if(i < n){\n" +
" a[i] = 2.f*a[i];\n" +
" }\n" +
"}";
//IOUtils.readText(new File("TutorialKernels.cl"));
CLProgram program = context.createProgram(src).build();
// Get and call the kernel :
CLKernel addFloatsKernel = program.createKernel("add_floats");
addFloatsKernel.setArgs(a, n);
CLEvent evt = addFloatsKernel.enqueueNDRange(clQueue, new int[] { n });
aPtr = a.read(clQueue, evt); // blocks until add_floats finished
// Print the first 10 output values :
for (int i = 0; i < 10 && i < n; i++) {
System.out.println("out[" + i + "] = " + aPtr.get(i));
}
}