Search Unity

Feedback Feature request: add AndroidJNI.GetDirectBufferAddress

Discussion in 'Android' started by jyrkive, Jun 1, 2021.

  1. jyrkive

    jyrkive

    Joined:
    Nov 14, 2016
    Posts:
    5
    Hi,

    Android version of my game has large assets in StreamingAssets and needs fast random access to them. It turns out to be difficult to achieve since StreamingAssets aren't exposed as regular files on Android: https://docs.unity3d.com/Manual/StreamingAssets.html

    Unity suggested workaround is UnityWebRequest, but it's not designed for random access, not even with a custom downloader.

    I decided to just memory-map the assets in Java code and expose them to C# by utilizing code akin to https://github.com/syaringan357/And...in/java/com/zwp/mobilefacenet/MyUtil.java#L79

    However, lack of AndroidJNI.GetDirectBufferAddress() makes it more complicated. Without it the only thing I have is a java.nio.Buffer object: GetDirectBufferAddress() would be the final step of getting a raw pointer out of it I could use without Java call overhead.

    As a workaround I'll just call JNIEnv::GetDirectBufferAddress() in C++ code instead, but it would be good if that step didn't require native code in a future Unity version.
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Registered a task investigating the area (this issue and some others I could remember).
    No promises or timelines though.
     
  3. jyrkive

    jyrkive

    Joined:
    Nov 14, 2016
    Posts:
    5
    Happy to hear that. :) (I also got my C++ version working in the meantime.)