简体   繁体   中英

Converting Objective-C struct arrays to Java

I'm porting some Objective-C to Android. The source app stores a lot of data in structure arrays and has some high performing methods to do lookups into the arrays and calculations on the result sets to provide near real time analysis of points on a graph as the user drags a pointer around the graph with their finger. The calculation results are used to update values in various views surrounding the graph.

Here's an example which contain approx 7.5k structures.

structDataFeedReduced gFeedData[7662] = {
1233,@"",12.466667,26.166667,@"AARS",0,0,0,1.000000,-1,1,1,
6760,@"",15.816667,41.033333,@"DCTT",1,1,1,12.000000,-1,1,2,
8117,@"",44.016667,144.283333,@"SKDD",2,1,2,9.000000,-1,1,1,
8666283,@"WS",42.676666,40.006668,@"DLCC",3,2,3,-5.000000,-1,1,6,
...
...
...
};

My question is what is the best way to store this data statically in Java?

I've tried the following which are not high enough performance, either at load time or to provide data to the calculations at run time.

  1. SQL Lite.
  2. Reading from files stored in assets.
  3. Storing statically as string arrays then processing them in initialisation into objects, using a class which mirrors the Objective-C structure (eg converting to int, bools, doubles etc from the string data)
  4. Storing in arrays.xml then processing them in initialisation into objects

Are there any other patterns I could try? If there are none, then I'll favour 3 or 4 above as I'll sacrifice some loading and initialisation performance for good runtime response.

My backstop would be to push this down into native code using JNI. Perhaps this is the only option that makes sense?

Thanks...

You can just keep that data as code. You could define a StructDataFeedReduced class, then change your initialization code to:

static StructDataFeedReduced[] gFeedData = new StructDataFeedReduced[] {
    new StructDataFeedReduced(1233,"",12.466667,26.166667,"AARS",0,0,0,1.000000,-1,1,1),
    new StructDataFeedReduced(6760,"",15.816667,41.033333,"DCTT",1,1,1,12.000000,-1,1,2),
    ...
}

The constructor of StructDataFeedReduced can store the data in internal fields as appropriate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM