David Gilbert wrote:
Regarding 3) and BufferedImages, I think I recall Sven saying he was mistaken about the DataBuffer classes. As far as I could tell (from writing some Mauve tests for them) they use real Java arrays.

It should be possible to have a hybrid implementation that can use
native buffers or Java arrays.  If constructed using (say)
  DataBufferInt(int size, int numBanks)
then it can allocated a native buffer.
The complicatation is getData and getBankData.  If using native buffers,
these would have to allocate new buffers, copy the data of of the
native buffers, release the native buffers, and switch to using the
Java arrays for future references.

This isn't too bad if you're using CNI and a non-copying gc, since
you can use a "native pointer" in all cases, and just have the
natve pointer point into the Java arrray in the Java case.
If using a copying GC, you can use a delta.  For simplicity, I
assume a single bank:

DataBufferInt {
  int[] array;
  native size_t offset;

  int getElem(int i) { return *(int*)((char*) array + offset + 4 * i); }

  DataBufferInt(int size) {
    void* buf = allocate_native_buffer(size);
    array = null;
    offset = buf;
  }

  DataBufferInt(int[] arr) {
     array = arr;
     offset = SIZE_OF_ARRAY_HEADER;
  }

  int[] getData () {
    int[] ar = new int[size];
    copy_form_native_buffer_into(ar);
    array = ar;
   offset = SIZE_OF_ARRAY_HEADER;
  }
}

This works even if the array is moved by the gc.
--
        --Per Bothner
[EMAIL PROTECTED]   http://per.bothner.com/


_______________________________________________
Classpath mailing list
Classpath@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath

Reply via email to