Hello,
I’ve a c function that updates (pass by parameter) a pointer to a structure. so in @ccall I should use Ptr{my_struct} types . But I cannot create the structure pointer as method pointer(whatever::MyStruct) does not exist… What is the best way to achieve that ?
Thks a lot
Br Yves-Julien
edit: I already have a solution but really not sure it’s the best i.e. using a pointer to vector of Uint8 of corresponding size and reinterpret the binary data to correct types
Thanks, this works ! I was confused because I tried a more concise way that work only I think if the structure is used as input to the function as below:
But if the functions changes the structure, it is not reflected in the julia structure. To my understanding it’s because the pointer is created in the function call thus valid only at function call so the after it is GC and therefore could not alter the content of mydata…
Am I correct ?
That identifier there — mydata — is just a name for you that can serve as a name for the value MyStruct(1). MyStruct itself is not mutable; it cannot change. And mydata can only become the name of a different thing if you explicitly assign something else to it, deciding you have a better use for that name.
When you put a value in a box like a Ref, then you (or your C code) can decide to switch out what’s on the inside of that box. If you throw away the box (or just don’t name it anything meaningful), then you won’t be able to observe the change.
In short, Julia’s variables don’t have the same pointer semantics that you might be used to.