I'm frustrated even more now. How I could create o...
# kotlin-native
k
I'm frustrated even more now. How I could create object MyKotlinObjectA (from my kotlin lib) and use it in swift application? Do I understood correctly, that accessing its fields (fields are mutable) should always performed from same single thread? E.g. If I created object in swift background thread, I can't read/update its values in swift UI thread.
k
Object called from different threads will need to be frozen. You can't have directly mutable fields
You can have atomic fields and mutate them that way, but without knowing your use case I don't know how much sense that makes
k
Mutable fields are nested lists and maps + other primitives.
If they need to be mutable, does it also means that I can't make cache inside my kotlin code, and all caches should be created in Swift? In that case, where I need to run code in different threads.
k
It means you can do it the way you’re doing it now. You can have some form of immutable list that you edit on copy. There was a post not too long ago with a link to something the native team does. I did some caching in c++ but that’s a long story
h
So in a frozen objec if I want to do caching I'll have to do
val cache = AtomicReference<Map<String, MyFrozenObject>>
, and then recreate and set map each time I update the cache?
k
1. Currently my code doesn't work, as i can't find easy way to pass objects between threads and keep them mutable. 2. Using immutable collections to operate data would be to slow with my data.
k
If you copy your collection on edit, which is the first of three things I mentioned, and obviously not a good choice for data with frequent changes, you’ll have bad performance. I can’t find the earlier link as I’m walking around Amsterdam. Anything of higher performance will require something a bit more exotic, but fundamentally you have to have safe data between threads
👍 1
h
Would like to hear more from you about how thread local state and being able to only access frozen objects from different threads reconcile with each other on KotlinConf. Sutff is very confusing
k
Db c++ code. It’s been a while so I may not approve of my own methods
If you’re here go to this
message has been deleted
👍 2
k
Would be great to see livestream form Granbeurszaal 😉
k
+1 on that
s
Too bad it's not live streamed 😞