• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Cannot use Kotlin object pinnig to pass a buffer to a C function

I am working on an app, and I need to pass a buffer of audio data from kotlin to a C function. The prototype of the C function is :
DECL(void, fftBuildAudioData, const jshort* const recordedAudio)

(DECL is a macro to declare the good prototype and name function to match JNI specifictions)

I saw in the Kotlin web page that kotlin is abble to pass pointer to C code with object pinning So I tried to write this code on my kotlin file :

private var recordedAudioData = ShortArray(4096)

//Reading data from an audio record instance

recordedAudioData.usePinned { pinned -> {



But when I compile I have this error :
 Unresolved reference: usePinned

I know I can use the env function GetShortArrayElements but the function may involve a copy of the initial array and I don't want that so I cannot use it.

My question is: how can I pass a Kotlin ShortArray as a pointer to a native c function if the way provided by the language doesn't work (I use Android Studio v2020.3.1 Patch 2)?


We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.