Sebastian Keller
03/13/2019, 12:59 PMCPointer<BooleanVar>
without the use of the nativeHeap? I would like to create one on the stack, but everything i've tried failed.
Currently im using this
val flag = nativeHeap.alloc<BooleanVar>(); flag.usePinned { it.get().ptr /* <- CPointer<BooleanVar> */}
Sebastian Keller
03/13/2019, 1:02 PMfun fileExistsAtPath(path: String, isDirectory: CPointer<BooleanVar?): Boolean
(iOS) and want to know if path
is a directory or not.jonnyzzz
03/13/2019, 1:07 PMcValue<T>(){...}
function to allocate a Var.
The memScope{..}
block is a replacement for nativeHeap
, it releases all allocations at the end of the blockSebastian Keller
03/13/2019, 1:10 PMSebastian Keller
03/13/2019, 1:11 PMbool b = false; bool *ptr = &b; functionThatUsesBoolPtr(ptr);
jonnyzzz
03/13/2019, 1:16 PMimport kotlinx.cinterop.BooleanVar
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.alloc
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.value
fun x(b: CPointer<BooleanVar>?) = 42
val test = memScoped {
x(alloc<BooleanVar> { value = false }.ptr)
}
where alloc
is the function that is available inside the memScoped
block. It allocates the booleanSebastian Keller
03/13/2019, 1:17 PM