Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6956723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:54:24+00:00 2026-05-27T14:54:24+00:00

I have an Android project (targeting Android 1.6 and up) which includes native code

  • 0

I have an Android project (targeting Android 1.6 and up) which includes native code written in C/C++, accessed via NDK. I’m wondering what the most efficient way is to pass an array of bytes from Java through NDK to my JNI glue layer. My concern is around whether or not NDK for Android will copy the array of bytes, or just give me a direct reference. I need read-only access to the bytes at the C++ level, so any copying behind the scenes would be a waste of time from my perspective.

It’s easy to find info about this on the web, but I’m not sure what is the most pertinent info. Examples:

Get the pointer of a Java ByteBuffer though JNI

http://www.milk.com/kodebase/dalvik-docs-mirror/docs/jni-tips.html

http://elliotth.blogspot.com/2007/03/optimizing-jni-array-access.html

So does anyone know what is the best (most efficient, least copying) way to do this in the current NDK? GetByteArrayRegion? GetByteArrayElements? Something else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:54:25+00:00Added an answer on May 27, 2026 at 2:54 pm

    According to the documentation, GetDirectBufferAddress will give you the reference without copying the array.

    However, to call this function you need to allocate a direct buffer with ByteBuffer.allocateDirect() instead of a simple byte array. It has a counterpart as explained here :

    A direct byte buffer may be created by invoking the allocateDirect
    factory method of this class. The buffers returned by this method
    typically have somewhat higher allocation and deallocation costs than
    non-direct buffers. The contents of direct buffers may reside outside
    of the normal garbage-collected heap, and so their impact upon the
    memory footprint of an application might not be obvious. It is
    therefore recommended that direct buffers be allocated primarily for
    large, long-lived buffers that are subject to the underlying system’s
    native I/O operations. In general it is best to allocate direct
    buffers only when they yield a measureable gain in program
    performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Android pet-project DroidIn which utilizes HttpClient 4 (built into Android) to do
I have an Android project that uses a library project (all of which I
I have a little Android project going on which involves some IPC where client
We have an Android/Blackberry project with a common part. That part, obviously, is written
I have a android project which feeds XML data from URL from web. I
I have an Android Maven project, which uses pure Java libs, I've struggled with
I have an Android test project in which I test my main application. The
in an android-project I need to have a checkbox which may have an indeterminate
I have an Android project which included a class with a file copy method.
I have a Android project which I'm building in Ant and I'm stuck on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.