Combining Jmonkeyengine with NDK

So as of late I’ve been having memory issues when dealing with an android port of my game. Optimizing is fine and all but I decided to also look into other options, seeing as I’ve seen various mobile games that doesn’t quite seem to follow the normal memory limits.

Among my answers was to use NDK to essentially get around the memory limitations. Now my question is:

Is it actually possible to combine the two together? I can’t say I’m well versed in C but I was under the impression that the most straightforward way of offloading memory to C code was to throw things like images, textures to the other side. However doesn’t JME do most of those things for you? With you basically just providing the path. When it’s like that, I’m unsure on how to go about actually using NDK with JME, though of course I suppose normal data can still work. Just not sure how much it would actually help with the memory problems.

JME tells (on desktop android might differ, but probably not much) lwjgl to upload the texture to the gpu.
At least on desktop it keeps a memory copy of it.
Both should be in Directbuffers already, so probably already on the native side.

In theory (i dont know how much it breaks) you could null the texturebuffers on jme side after they are uploaded.

So half is already done by jme, you only need to kill the java side copy of it later.
→ Potential sideeffects may be that the graficdriver acceses the pointer it is given into the directbytebuffer later (when you already deleted it), read up the opengl specification if this is possible.

Except when loading the data through the assetManager (which for speed reasons sometimes happens though java arrays) there is no additional copies of the textures (or anything else), the native buffers are directly used by OpenGL (which still makes a copy for the GPU but you can’t avoid that).

@OP: If you don’t know how then how do you think you’ll come up with native code that could help :chimpanzee_confused:

Well i meant the cpu side version, theoretically it could be deleted once it is uploaded.