Passing char*


#1

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


#2

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());


#3

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