I have a CFunction that then takes a pointer to th...
# kotlin-native
s
I have a CFunction that then takes a pointer to that pointer. So I actually need to do
&(PVOID&)foo
which is separately challenging me. PVOID is just an alias for void*. So I guess I need to figure out how to get the memory address of any particular CPointer (the actual pointer variable, not the pointed object).
d
That can't be done, you'll need another layer of indirection.
You can achieve this with
memScoped
and
alloc
.
s
Yeah I've been fiddling with that. It's a bit irritating to have to allocate additional heap memory assuming a global
val foo = staticCFunction
actually allocates on the heap like it would in cpp
@Dominaezzz Actually not so sure there's a way to get a pointer to the underlying variable.
d
It doesn't allocate I think. It's more like a cast.
There isn't a way because it means tampering with Kotlin memory "space".
k
i struggled with that for a while
s
Is the return value of memScoped properly reference counted/garbage collected?
k
the point of memScoped is to clean up memory allocated in the block