I am parsing a binary file on the device and storing fields I care about in arrays. These files can lead to arrays that are 100,000’s in size. Naturally, java tells me I run out of memory (I think android only allows 16MB per application).
Is there another way to grab this data?
Basically, I parse for points and color information, store it in arrays, then use vertexBuffers to draw these in OpenGL. Storing them in a database wouldn’t help me, would it?
Thank you!
EDIT:
I run a parse on a file with 482,000 points. It stores position and color without crashing. I see this in debugger:
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
The error populates on java.nio.ByteBuffer.allocateDirect
I’ve included that code area below:
//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);
}
I don’t know if it could help you, but there are lots of interresting advices from google aubout memory management here: http://dubroy.com/blog/google-io-memory-management-for-android-apps/