gpt4 book ai didi

Android OutOfMemory 问题

转载 作者:行者123 更新时间:2023-11-29 14:06:43 25 4
gpt4 key购买 nike

我正在解析设备上的二进制文件并将我关心的字段存储在数组中。这些文件可以生成大小为 100,000 的数组。自然地,java 告诉我内存不足(我认为 android 每个应用程序只允许 16MB)。

还有其他方法可以获取这些数据吗?

基本上,我解析点和颜色信息,将其存储在数组中,然后使用 vertexBuffers 在 OpenGL 中绘制这些信息。将它们存储在数据库中对我没有帮助,对吗?

谢谢!

编辑:我对一个包含 482,000 点的文件运行解析。它存储位置和颜色而不会崩溃。我在调试器中看到了这个:

Grow heap (frag case) to 43.164MB for 23156032-byte allocation
Forcing collection of SoftReferences for 30874704-byte allocation
Out of memory on a 30874704-byte allocation

错误出现在 java.nio.ByteBuffer.allocateDirect 上我在下面包含了该代码区域:

//Parse file and populate arrays
PointParser(fileName, header);

// a float is 4 bytes, therefore we multiply the number if
// vertices with 4.
ByteBuffer vbb = ByteBuffer.allocateDirect(lasVertices.length * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(lasVertices);
vertexBuffer.position(0);

ByteBuffer cbb = ByteBuffer.allocateDirect(lasColors.length * 4);
cbb.order(ByteOrder.nativeOrder());
colorBuffer = cbb.asFloatBuffer();
colorBuffer.put(lasColors);
colorBuffer.position(0);

...

public void draw(GL10 gl) {
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glPointSize(0.6f);
gl.glDrawArrays(GL10.GL_POINTS, 0, numVertices);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}

最佳答案

我不知道它是否能帮到你,但这里有很多来自 google aubout 内存管理的有趣建议:http://dubroy.com/blog/google-io-memory-management-for-android-apps/

关于Android OutOfMemory 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6540021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com