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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:42:10+00:00 2026-06-01T10:42:10+00:00

Can I use a native method which returns a pointer? I used the following

  • 0

Can I use a native method which returns a pointer?
I used the following syntax:
public native int* intArrayMethod(float[] t,int nb_of_subscribers,int tags);
but it indicates an error.

  • 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-06-01T10:42:11+00:00Added an answer on June 1, 2026 at 10:42 am

    You shouldn’t use native pointers in Java because of the differences in data structures between C++ and Java. And Java’s garbage collector.

    Your Java class should look like this:

        public class IntArrayViaJNI {
          private static boolean loaded = false;
          private native int[] intArrayMethod(float[] t, int nb_of_subscribers, int tags);
    
          public int[] getIntArray(float[] t, int nb_of_subscribers, int tags) {
              // Although this portion should be in a synchronized method,
              // e.g. ensureLibraryLoaded().
              if (!loaded) {
                System.loadLibrary("mylib");
                loaded = true;
              }
              return intArrayMethod(t, nb_of_subscribers, tags);
          }
        }
    

    And your C++ code should look like this:

        JNIEXPORT jintArray JNICALL Java_IntArrayViaJNI_intArrayMethod(
            JNIEnv *env, jclass cls,
            /* generated by JAVAH: float[] t, int nb_of_subscribers, int tags */)
        {
          jintArray result = (*env)->NewIntArray(env, size);
          if (result == NULL) {
            return NULL; /* out of memory error thrown */
          }
          int i, size = MY_ARRAY_SIZE;
    
          // Populate a temp array with primitives.
          jint fill[256];
          for (i = 0; i < size; i++) {
            fill[i] = MY_ARRAY_VALUE;
          }
    
          // Let the JVM copy it to the Java structure.
          (*env)->SetIntArrayRegion(env, result, 0, size, fill);
          return result;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway I can use native javascript to fire an event called onmove
In C++/CLI , you can use native types in a managed class by it
I can't seem to find an easy to use, .net native way to get
You can use a standard dot notation or a method call in Objective-C to
I am developing a library for Android applications which does not use native code
Is there any method I can send to an object, which will return an
I have a class like this: public final class Foo { public native int
I have a C++/CLI project that wraps a native C++ application, which I use
I am trying to use JNotify for my application , which has the following
You can use more than one css class in an HTML tag in current

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.