How to pass pointers over interface calls
version
1.0.0
scope
Example.
This code is provided as example code for a user to base their code on.
description
How to pass pointers over interface calls
boards
Unless otherwise specified, this example runs on the SliceKIT Core Board, but can easily be run on any XMOS device by using a different XN file.
Interface functions can take pointer arguments:
interface my_interface { void msg(int *p); };
The client end can then pass a pointer into the function:
void task1(client interface my_interface c) { int a[5] = {0,1,2,3,4}; int *p = &a[0]; c.msg(p); }
On the server end the select case can access memory via the pointer.
void task2(server interface my_interface c) { select { case c.msg(int *p): printintln(*p); printintln(*(p+2)); break; } }
Since passing the pointer implies that both tasks need access to the same memory space, if an interface includes a function that passes pointers, you cannot use it between tasks on different tiles.