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

  • SEARCH
  • Home
  • 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 7128735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:10:10+00:00 2026-05-28T11:10:10+00:00

Suppose that I have a C data-structure containing many data fields (>15): struct MyData

  • 0

Suppose that I have a C data-structure containing many data fields (>15):

struct MyData
{
   int x;
   float y;
   ...
}

In Java, I can store a pointer to a MyData as a long, and access members of the C data structure through JNI calls:

long mydata_p = MyDataJNI.alloc();

int x = MyDataJNI.getX( mydata_p );
float y = MyDataJNI.getY( mydata_p );
...

However, the calls to these functions are shockingly expensive (10x-100x the cost of an equivalent C function call). This is true even if the implementation getX, getY, … is as simple as:

return ((MyData*)())->x

Q1: Why are JNI calls so expensive? What else is going on other than a call to a function pointer? (For reference, I’m looking at JNI calls in Android.)

Q2: What is the fastest what to make all of the elements of my C structure available at the Java layer?

  • 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-28T11:10:10+00:00Added an answer on May 28, 2026 at 11:10 am

    You want to move all of the data with a single JNI call. You can either copy it into a primitive byte array (and then extract Java primitives from that using some combination of ByteArrayOutputStream and DataOutputStream), or use a direct NIO ByteBuffer (ByteBuffer.allocateDirect), which makes more sense if you need to move data back and forth. The direct ByteBuffer is specifically designed and optimized for sharing memory between the VM and native code.

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

Sidebar

Related Questions

Suppose that you have a data frame with many rows and many columns. The
I have the following json and suppose that I can't modify it: { structure:
Suppose I have a function that will return a large data structure, with the
Suppose I have my node structure as: struct Employee { int age; int salary;
Suppose that you have a big Data Entry Web Application Like Microsoft CRM ,
Suppose I have a class that processes some data: class SomeClass { public: void
Suppose that I have a Java program within an IDE (Eclipse in this case).
Suppose that I have a Java class with a static method, like so: class
Suppose that you have to set 12 cookies, would it be better to store
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items

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.