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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:43:59+00:00 2026-05-22T19:43:59+00:00

I have found large amounts of documentation on how to generate a 2D primitive

  • 0

I have found large amounts of documentation on how to generate a 2D primitive array in JNI and returning it to Java. But these pieces of information fail to describe how to pass an already existing 2D float array (float**) given a context in C.

To describe my issue explicitly, I’ll add some C pseudo code of what I would like to implement:

// Returns a 2D float array from C to Java
jfloatArray ndk_test_getMy2DArray(JNIEnv* env, jobject thiz, jlong context)
{
    // Cast my context reference
    MyContextRef contextRef = (MyContextRef) context;

    // In case we need it below
    unsigned int length = MyContextGet1DLength(contextRef);

    // Get the 2D Array we want to "Cast"
    float** primitive2DArray = MyContextGet2DArray(contextRef);

    // Hokus pokus...
    // We do something to create the returnable data to Java
    //
    // Below is the missing piece that would convert the primitive
    // 2D array into something that can be returned consumed and consumed
    // by Java

    jfloatArray myReturnable2DArray

    return myReturnable2DArray;
}

I’m assuming this is not straight forward, given I haven’t been able to find anything describing this scenario.

Thanks for any helpful information.

  • 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-22T19:44:00+00:00Added an answer on May 22, 2026 at 7:44 pm

    Thanks Timo for your help and link. For posterity, I’m adding a complete code set that would go through the process of generating a 2D primitive array consumable by Java, from an existing C 2D primitive array.

    // Returns a 2D float array from C to Java
    jobjectArray ndk_test_getMy2DArray(JNIEnv* env, jobject thiz, jlong context)
    {
        // Cast my context reference
        MyContextRef contextRef = (MyContextRef) context;
    
        // Get the length for the first and second dimensions
        unsigned int length1D = MyContextGet1DLength(contextRef);
        unsigned int length2D = MyContextGet2DLength(contextRef);
    
        // Get the 2D float array we want to "Cast"
        float** primitive2DArray = MyContextGet2DArray(contextRef);
    
        // Get the float array class
        jclass floatArrayClass = (*env)->FindClass(env, "[F");
    
        // Check if we properly got the float array class
        if (floatArrayClass == NULL)
        {
            // Ooops
            return NULL;
        }
    
        // Create the returnable 2D array
        jobjectArray myReturnable2DArray = (*env)->NewObjectArray(env, (jsize) length1D, floatArrayClass, NULL);
    
        // Go through the firs dimension and add the second dimension arrays
        for (unsigned int i = 0; i < length1D; i++)
        {
            jfloatArray floatArray = (*env)->NewFloatArray(env, length2D);
            (*env)->SetFloatArrayRegion(env, floatArray, (jsize) 0, (jsize) length2D, (jfloat*) primitive2DArray[i]);
            (*env)->SetObjectArrayElement(env, myReturnable2DArray, (jsize) i, floatArray);
            (*env)->DeleteLocalRef(env, floatArray);
        }
    
        // Return a Java consumable 2D float array
        return myReturnable2DArray;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Java application for copying large amounts of data from users' workstations
I am developing a fairly large C++ support library, and have found myself moving
I have found the way to copy the record that I would like, but
I have found the Form.TopMost property but it puts the form on top of
I work for a transit agency and I have large amounts of data (mostly
I have found many questions here about storing values in viewstate, but haven't found
I have a small server that accepts large amounts of long-lasting connections from clients.
I have a UITabBar Application with two views that load large amounts of data
We have a java program that requires a large amount of heap space -
I have found myself designing a language for fun that is a cross between

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.