Passing char*

Dear JOCL users

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

Java Code:

Pointer srcText = Pointer.to(t);
cl_mem memObjectText = clCreateBuffer(context, 
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
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?

regards,
David

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 = Pointer.to(text.getBytes());

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)