diff options
author | Michael Bien <[email protected]> | 2011-04-05 23:01:25 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2011-04-05 23:01:25 +0200 |
commit | eb0aeae72378942509942314b346ad9ed30e1333 (patch) | |
tree | 1a88590a0de94d5d4dbaea317ee6a7239c6616b2 /src/com | |
parent | 9317b6018e7f4e95437204d93d45e4d83daac790 (diff) |
CachedBufferFactory constructors for CLEventList allows efficient creation of large amounts of small lists.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/jogamp/opencl/CLEventList.java | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/com/jogamp/opencl/CLEventList.java b/src/com/jogamp/opencl/CLEventList.java index f2b98adf..23ef3963 100644 --- a/src/com/jogamp/opencl/CLEventList.java +++ b/src/com/jogamp/opencl/CLEventList.java @@ -29,6 +29,7 @@ package com.jogamp.opencl; import com.jogamp.common.AutoCloseable; +import com.jogamp.common.nio.CachedBufferFactory; import com.jogamp.common.nio.PointerBuffer; import java.util.Iterator; @@ -51,24 +52,43 @@ public final class CLEventList implements CLResource, AutoCloseable, Iterable<CL final PointerBuffer IDsView; int size; - + public CLEventList(int capacity) { + this(null, capacity); + } + + public CLEventList(CLEvent... events) { + this(null, events); + } + + public CLEventList(CachedBufferFactory factory, int capacity) { this.events = new CLEvent[capacity]; - this.IDs = PointerBuffer.allocateDirect(capacity); + this.IDs = initIDBuffer(factory, capacity); this.IDsView = PointerBuffer.wrap(IDs.getBuffer()); } - public CLEventList(CLEvent... events) { + public CLEventList(CachedBufferFactory factory, CLEvent... events) { this.events = events; - this.IDs = PointerBuffer.allocateDirect(events.length); + this.IDs = initIDBuffer(factory, events.length); this.IDsView = PointerBuffer.wrap(IDs.getBuffer()); for (CLEvent event : events) { + if(event == null) { + throw new IllegalArgumentException("event list containes null element."); + } IDs.put(event.ID); } IDs.rewind(); size = events.length; } + + private PointerBuffer initIDBuffer(CachedBufferFactory factory, int size) { + if(factory == null) { + return PointerBuffer.allocateDirect(size); + }else{ + return PointerBuffer.wrap(factory.newDirectByteBuffer(size*PointerBuffer.elementSize())); + } + } void createEvent(CLContext context) { @@ -98,7 +118,7 @@ public final class CLEventList implements CLResource, AutoCloseable, Iterable<CL public final void close() throws Exception { release(); } - + public CLEvent getEvent(int index) { if(index >= size) throw new IndexOutOfBoundsException("list contains "+size+" events, can not return event with index "+index); |