* <p>
* Each object has a single memory pointer which is stored in the p field.
* For most objects this is the only value retained and all get methods defer
- * to the OpenCL runtime. OpenCL objects with the same pointer are guarnateed
+ * to the OpenCL runtime. OpenCL objects with the same pointer are guarnateed
* to map to the same Java instance. Objects are considered equal if their p
* value is identical.
* <p>
* function used to retrieve the information.
* <p>
* Memory management is automatic but can also be explicit at application
- * discretion. Use the release() methods for explicit deallocation.
+ * discretion. Use the release() methods for explicit deallocation.
*/
public abstract class CLObject extends Native {
super(p);
}
+ // for now ... mirror the native ones so native isn't exposed?
+ public static void release(CLObject list) {
+ if (list != null)
+ list.release();
+ }
+
+ public static void release(CLObject... list) {
+ for (CLObject o: list)
+ release(o);
+ }
+
// new 5-param version
// this one is static so it can be accessed at creation time
protected static MemoryAddress getInfo(MemoryAddress self, int id, MethodHandle getInfo, Allocator frame, long size) throws CLRuntimeException {
}
}
- protected <T extends CLProperty> T[] getInfoPropertyV(int id, MethodHandle getInfo, BiFunction<Long,Long,T> create, IntFunction<T[]> createArray) {
+ protected <T extends CLProperty> T[] getInfoPropertyV(int id, MethodHandle getInfo, BiFunction<Long, Long, T> create, IntFunction<T[]> createArray) {
try (Allocator a = Memory.stack()) {
return CLProperty.fromNative(getInfoAny(id, getInfo, a), create, createArray);
}
}
}
- protected <T extends CLObject> T[] getInfoAnyV(int id, MethodHandle getInfo, Function<MemoryAddress,T> create, IntFunction<T[]> createArray) {
+ protected <T extends CLObject> T[] getInfoAnyV(int id, MethodHandle getInfo, Function<MemoryAddress, T> create, IntFunction<T[]> createArray) {
try (Allocator a = Memory.stack()) {
return Native.toObjectV(getInfoAny(id, getInfo, a), create, createArray);
} catch (RuntimeException | Error t) {
static String infoToString(MemorySegment seg) {
if (false) {
MemoryAddress valp = seg.baseAddress();
- byte[] val = new byte[(int)(seg.byteSize()-1)];
+ byte[] val = new byte[(int)(seg.byteSize() - 1)];
- for (int i=0;i<val.length;i++)
+ for (int i = 0; i < val.length; i++)
val[i] = getByte(valp, i);
return new String(val);
} else {
byte[] val = seg.toByteArray();
- return new String(val, 0, val.length-1);
+ return new String(val, 0, val.length - 1);
}
}
int len = (int)(valp.byteSize() >>> 3);
long[] list = new long[len];
- for (int i=0;i<list.length;i++)
+ for (int i = 0; i < list.length; i++)
list[i] = getLong(val, i);
return list;