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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:03:14+00:00 2026-05-27T09:03:14+00:00

My java code will call the exist c++ code to parse the file. it

  • 0

My java code will call the exist c++ code to parse the file. it will generate an object which keep many data.
I will call the jni’s second method to access such data,
When I call the second method, I have to parse the file again. it is obviously the right behavior.

Is there a way to handle this ?
BTW: I am newly to c++.

  • 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-27T09:03:15+00:00Added an answer on May 27, 2026 at 9:03 am

    I am not sure if I understand your question correct. But I guess what you want to do is to keep some sort of c++ object alive over multiple jni calls.

    You can do multiple things. First parse your file and store your c++ object in a global variable. This is the simplest solution but not a nice one.

    You can also move the life cycle of your c++ object into java.

    jlong java_some_class_jni_method(...)
    {
        .... parse your text file ....
        MyParseclass* cls = new MyParseclass(...);
        ....
        return (jlong) cls;
    }
    

    But keep in mind that you need to delete this native c++ class again. So you need a jni method to this and be sure to call it.

    void java_some_calls_jni_method(..., jlong clsPtr)
    {
        MyParseclass* cls = (MyParseclass*)clsPtr;
        ... do maybe do something with cls and access the data...
        delete cls; // do not use the jlong again in any call
    }
    

    BTW: It would be much more helpful if you would post some code. But I hope this pseudo code here helps a little.

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

Sidebar

Related Questions

Is there a built in Java code that will parse a given folder and
I have written a piece of Java code which is intended as to call
Will Java code built and compiled against a 32-bit JDK into 32-bit byte code
I heard that JNBridge will translate C# code to native Java code.( I haven't
Our Java code (not the test code) reads files from the current directory, which
Given the following Java code for generating a binary file: DataOutputStream out = new
I'm looking for Java code that can be used to generate sound at runtime
Using the return keyword in Java code will return execution to the last piece
I need to create a porting software that will convert Java code to C#
I have a server program running a java binary code (xx.jar file). While it

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.