From eb0aeae72378942509942314b346ad9ed30e1333 Mon Sep 17 00:00:00 2001
From: Michael Bien <mbien@fh-landshut.de>
Date: Tue, 5 Apr 2011 23:01:25 +0200
Subject: CachedBufferFactory constructors for CLEventList allows efficient
 creation of large amounts of small lists.

---
 src/com/jogamp/opencl/CLEventList.java | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

(limited to 'src')

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);
-- 
cgit v1.2.3