So I have an `Array<Buffer>` object. The `Bu...
# kotlin-native
d
So I have an
Array<Buffer>
object. The
Buffer
class has a
COpaquePointer
property and I wanna pass a temp array of these pointers to a C function. There are 2 ways to do this,
cValuesOf(...)
and
memScope { allocArray(...) { ... } }
, which should I prefer and when?
o
it depends on what are you trying to achieve.
COpaquePointer
points somewhere, so question is how long you want that pointer to live. If as long, as the buffer itself, right approach would be to allocate pointer with arena, and dispose arena in special dispose method. See how disposable objects are managed in videoplayer sample: https://github.com/JetBrains/kotlin-native/blob/10b05b6229d99faaa97eaf92ae63d5da97e9be8c/samples/videoplayer/src/main/kotlin/SDLVideo.kt#L37
d
Oh no, I mean the
Buffer
class already has its
COpaquePointer
pointing to somewhere. I want to pass an array of all the buffer pointers to a C function. This array's lifetime is independent of the buffer's lifetime.
What if it's for a one off thing? A temp array that is copied on the C side.
o
then
cValuesOf()
or
Array.toCValues()
is the way to go