basher
02/21/2019, 1:53 AMInt
(or other primitive) without using alloc
in memScoped
? I'm trying to do it useing usePinned
, but i'm having trouble navigating the types. Is the the right direction?Dico
02/21/2019, 2:53 AMnativeHeap.alloc
. You can use .ptr
to get a pointer to the allocated memory. .value
to read it if it is a primitive. Any structure field turns into a property if you allocated a struct type.Dico
02/21/2019, 2:54 AMDico
02/21/2019, 2:55 AMusePinned
can only yield CPointer
if you use it on an array. pin.addressOf(0)
would give you what you want.Dico
02/21/2019, 2:56 AMKNativePtr
cannot be used as a CPointer
because it refers to a kotlin object, which is managed by the virtual machine, so it would be unsafe if you could use it as a CPointer
.Dico
02/21/2019, 2:59 AMmemScoped
is something that C does not have, which just makes memory management more safe and simple in Kotlin. But I am sometimes worried about its performance. Haven't tested it though. Nonetheless, if theres a function i expect to use a lot, I prefer allocating memory for it for the remainder of the process's life.basher
02/21/2019, 3:26 AMolonho
02/21/2019, 4:57 AMbasher
02/21/2019, 5:11 AMolonho
02/21/2019, 5:25 AMuli
02/21/2019, 5:55 AMDominaezzz
02/21/2019, 11:30 AMalloca
in kotlin? Would it work without any.... quirks?svyatoslav.scherbina
02/21/2019, 11:51 AMbasher
02/21/2019, 2:29 PMDominaezzz
02/21/2019, 2:31 PMmemScoped
is indeed only a wrapper around nativeHeap
.