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 7414545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:07:18+00:00 2026-05-29T07:07:18+00:00

I want to pass a 3d float array(float[][][]) from java to c edit it

  • 0

I want to pass a 3d float array(float[][][]) from java to c edit it and return the array back to java
Curretly i can do this only with 1D arrays with this

jfloat* valuesjf = NULL;
float* valuesf = NULL;
void Java_Grids_Grid5_Update( JNIEnv* env,jobject thiz,jfloatArray values )
{
    valuesjf = (*env)->GetFloatArrayElements(env,values,NULL);
    valuesf = valuesjf;

    valuesf[0]=121+valuesf[0];//do some calculations

    (*env)->ReleaseFloatArrayElements(env, values, valuesjf, JNI_ABORT);
}

How do i do it with 3D array?

  • 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-29T07:07:18+00:00Added an answer on May 29, 2026 at 7:07 am

    You could flatten the 3d float array in Java into a 1d array. You can then access each element of the original 3d array by generating the correct index into the 1d array. You would also need to pass the length of each dimension of the array to the native method so that the native method can also generate the correct indices into the 1d array

    Java:

    // The lengths of each dimension of the values array
    int l, m, n;
    // Instead of:
    // float[][][] values = new float[l][m][n];
    // Do this:
    float[] values = new float[l * m * n];
    
    // To access an entry at (x, y, z) in the array.
    // Instead of:
    // float v = values[z][y][x];
    // Do this:
    int i = (m * n * z) + (n * y) + x;
    float v = values[i];
    

    C++:

    // You should not store a reference to the Java array as a global variable.
    // The reference is only valid between the Get/ReleaseFloatArrayElements calls
    // Since valuesf is assigned the same reference to the Java array,
    // the same advice also applies to it
    // jfloat* valuesjf = NULL;
    // float* valuesf = NULL;
    
    void 
    Java_Grids_Grid5_Update(JNIEnv* env,
                             jobject thiz,
                             jfloatArray values,
                             jint l, jint, m, jint n) {
    
      jfloat* valuesjf = (*env)->GetFloatArrayElements(env,values,NULL);
      float* valuesf = valuesjf;
    
      int x, y, z;
      int i = (m * n * z) + (n * y) + x;
      valuesf[0]=121+valuesf[i]; //do some calculations
    
      (*env)->ReleaseFloatArrayElements(env, values, valuesjf, JNI_ABORT);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I simply want to pass from top to bottom as a hover, but the
I want to know that how can I pass UIColor's name to the specific
How do I pass back a local variable from a function to main ,
I want to pass an integer value to a form in .Net so that
I want to pass an int list (List) as a declarative property to a
I want to pass an enum value as command parameter in WPF, using something
I want to pass in the tType of a class to a function, and
I want to pass some parameters to my MVC UserControl like ShowTitle(bool) and the
I want to pass a variable to a UIButton action, for example NSString *string=@one;
I want to pass a byte[] to a method takes a IntPtr Parameter in

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.