Passing char*


Dear JOCL users

I wrote a Java program where I pass an char array to a char*:

Java Code:

Pointer srcText =;
cl_mem memObjectText = clCreateBuffer(context, 
Sizeof.cl_char * t.length, srcText, null);

OpenCL Code:

__kernel void patternmatch(__global const char *t, long tn, int k, __global int *r)

Now I realized that somehow the following happens:

Text to pass: “ABCD”
Text Arrived: “A B C D” (space between the charaters)

Any ideas to remove that?



Just found the issue.

Char in Java is 2 Bytes, char in opencl is 1 Byte. So instead of using the char array, using the byte array:

Pointer srcText =;


That’s right: A C/OpenCL char consists of 1 byte, and has to be represented by a byte in Java (because in Java, char has two bytes - basically to support unicode)