Adam S
12/20/2023, 6:23 PMcreateValues()
is creating an CValues with size 24 instead of 3.
Is there a way to create CValues with a specific size?
import kotlinx.cinterop.*
fun main() {
nativeHeap.cValuesOf(listOf("1", "2", "3"))
}
typealias StringPointer = CPointerVarOf<CPointer<ByteVar>>
fun NativePlacement.cValuesOf(strings: List<String>): CValues<StringPointer> {
println("strings.size ${strings.size}")
val array = createValues<StringPointer>(strings.size) { i ->
val str = strings[i].cstr
val arr = allocArray<ByteVar>(str.size)
str.place(arr)
}
println("strings array.size ${array.size}")
return array
}
prints:
strings.size 3
strings array.size 24
Oleg Yukhnevich
12/20/2023, 6:37 PMcreateValues
,
array.size
returns amount of bytes in CValues
- in this case you create CValues
where there are 3 pointers (each of 8 bytes)
What do you need this for?Oleg Yukhnevich
12/20/2023, 6:38 PMcreateValues
at all, so probably in the end it will be anyway empty ^_^Adam S
12/20/2023, 6:38 PMint ListView(const char **text, int count);
Adam S
12/20/2023, 6:39 PMpublic expect fun GuiListViewEx(text: CValuesRef<CPointerVar<ByteVar>>?, count: Int): Int { /* compiled code */ }
Adam S
12/20/2023, 6:42 PMyou are not using receiver ofAhh yes, good spot. I assumed it would be a builder like
List(5) { i -> ...}
Oleg Yukhnevich
12/20/2023, 6:42 PMallocArray(strings.size) { value = strings[it].cstr.ptr }
most likely last ptr
need to be replaced with .getPointer(this)
because you need NativePlacement
but .ptr
declared in MemScope
Adam S
12/20/2023, 6:45 PMallocArray()
returns CArrayPointer<>
, but I need CValues<>
Adam S
12/20/2023, 6:45 PMOleg Yukhnevich
12/20/2023, 6:45 PMAdam S
12/20/2023, 7:04 PM