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.
- SQL Lite.
- Reading from files stored in assets.
- Storing statically as string arrays then processing them in initialisation into objects, using a class which mirrors the Objective-C structure (e.g. converting to int, bools, doubles etc from the string data)
- 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
StructDataFeedReducedclass, then change your initialization code to:The constructor of
StructDataFeedReducedcan store the data in internal fields as appropriate.