简体   繁体   English

Android:在Android Studio中存储大型固定阵列

[英]Android: Storing large fixed arrays in android studio

I am trying to use a 2d array to do some mapping in android. 我正在尝试使用2d数组在android中进行一些映射。 Basically the task is to convert polar coordinates to cartesian coordinates(both coordinates have to be integers). 基本上,任务是将极坐标转换为笛卡尔坐标(两个坐标必须为整数)。 This conversion is used to pick a value at the calculated X and Y coordinates. 此转换用于在计算的X和Y坐标处选择一个值。

I have an r and that input that needs to return x and y . 我有一个r和那个需要返回xy输入。 (int)(R + rcostheta) and (int)(R - rsintheta) will give me the required values (since my original cartesian matrix is 2R * 2R ). (int)(R + rcostheta)(int)(R - rsintheta)将给我所需的值(因为我的原始笛卡尔矩阵为2R * 2R )。 But calculating them repeatedly is causing a lot of overhead. 但是反复计算会导致大量开销。 So i decided to pre-calculate the values of these so that i can avoid calculations. 因此,我决定预先计算这些值,以便避免计算。 (And these calculations do take around 2-3 second overhead when I run my code) (当我运行我的代码时,这些计算确实需要大约2-3秒的开销)

ie, instead of using Value[x][y] , I can use 即,除了使用Value[x][y] ,我还可以使用

Value [ X[r][theta] ] [ Y[r][theta] ]

However this conversion matrix/2d array is pretty large. 但是,此转换矩阵/ 2d数组非常大。 It has 128 x 960 elements (my applications has 128 radius and 960 segments). 它具有128 x 960个元素(我的应用程序具有128个半径和960个段)。 I keep getting a "code too large" error. 我不断收到“代码太大”错误。

Can you suggest an easy way to implement this? 您能建议一个简单的方法来实现这一点吗? ie, to store this mapping matrix somewhere where it can be referenced without too much overhead. 即,将该映射矩阵存储在无需过多开销即可被引用的位置。

Some people suggest using a database. 有人建议使用数据库。 But since I am new to android programming it looks a little bit scary. 但是由于我是android编程的新手,所以它看起来有些吓人。 Surely it can be done a lot simpler? 当然可以简化很多吗?

Currently I am storing my two mapping matrices as 目前,我将两个映射矩阵存储为

int[][] X = new int[][]{
                 {229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356},

{next line},
.
.
.
{last line};

And using it as 并将其用作

getBinary(tempBitmap, X[j][i],Y[j][i]);

This should work if the X and Y matrices were smaller. 如果X和Y矩阵较小,这应该起作用。 But since they are gigantic, I cant do it. 但是由于它们巨大,所以我做不到。 Please suggest a way to go about doing this. 请提出一种执行此操作的方法。

The computation doesn't look like it should take a long time - is it because you are you doing a large number of these calculations? 计算似乎不需要花费很长时间-是因为您要进行大量这些计算吗?

If a typical run of your application only uses a relatively small number of points, but does the conversion on them many times, then it would probably be best to do the calculation the first time that it's needed, and cache the result (in memory, if there isn't going to be a huge number of them). 如果您的应用程序的典型运行仅使用相对较少的点,但是对它们进行了多次转换,那么最好是在第一次需要时进行计算,然后将结果缓存(在内存中,如果不会有很多)。

If that's not going to work, then the next logical thing to do would indeed be to put the values into the database. 如果这不起作用,那么接下来要做的逻辑确实是将值放入数据库中。 This is a very common thing to do in an Android application, and there are a large number of tutorials available on the internet, in books, etc. 这在Android应用程序中是很常见的事情,互联网,书籍等中都有大量的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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