How to map an array of custom objects between kotlin-native and c

I use kotlin multiplatform to develop a shared library for android and windows and have a custom data exchange object to interact between the library and the main program.

My kotlin library provides some functions like this:

fun doSomeGreatStuff(input: Array<CustomData>)  : Array<CustomData> {....}

Where CustomData is a data class that contains a bundle of properies.

On the C side, I have a std::list object which contains my CustomData objects. But how can I map this list into the kotlin list and vice versa?

To convert kotlin to c it something like this, I think. But I can’t set the value

 fun List<Media>.toCArray() = memScoped {

          val cArray = allocArray<CPointer<CustomData>>(size)
          forEachIndexed() { index, value ->
                     cArray[index] = value.objcPtr() //doesnt work

Must I implement CVariable for this?

best greetings and thank you

Hello, @swi! Can you clarify a little bit, are those classes interop’ted from the C side, or you declare them in Kotlin?

Hi @Artyom.Degtyarev. All clases are part of the kotlin code and compiled as a dynamic library.
One of them is a data class.
This library I included in c++ project. In this project I want to create a list of CustomData and Media objects and calling some kotlin functions.
The list of objects is one argument of the kotlin function. The kotlin functions also returns a List of this objects. So, how to map the lists between kotlin and c?