Author Topic: How to estimate the memory-usage in jPCT-AE?  (Read 4575 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
How to estimate the memory-usage in jPCT-AE?
« on: August 02, 2012, 06:20:15 am »
I have read this: http://www.jpct.net/wiki/index.php/Reducing_memory_usage

But i want to know more. Thanks!

 How to estimate the memory-usage of an Object3D obj with some known attributes(such as  triangles、vertexs and so on )? For examble: How many memories will the jPCT-AE allocate when loading a 6000-triangles model? And what's the situation when invoke methods of this Object3D obj?

 How to estimate  the memory-usage of a texture? Is that right: 
 
  1,   By default,  a 256*256 texture will need 256*256*4 bytes memory when "new texture(...)".
  2.a,  If enable "defaultToKeepPixels", there will need another 256*256*4 bytes when "World.draw(...)"(if enable4bpp then will be 256*256*2 bytes).
  2.b,  If disable "defaultToKeepPixels", there will need no extra memory when uploaded to gpu.

  How to estimate the memory-usage of both keyframe-animation and bones-animation?

  What's the situation when i use FrameBuffer.blit(...)?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #1 on: August 02, 2012, 07:52:39 am »
Quote
How to estimate the memory-usage of an Object3D obj with some known attributes(such as  triangles?vertexs and so on )? For examble: How many memories will the jPCT-AE allocate when loading a 6000-triangles model? And what's the situation when invoke methods of this Object3D obj?
To be honest, i don't know. It also depends on the object itself, i.e. how many vertices can be shared, how many texture stages will be used, if you call strip() on it or not etc. I would say: Take your object and give it a try. Calling any methods on an Object3D usually has no effect on memory usage.

Quote
1,   By default,  a 256*256 texture will need 256*256*4 bytes memory when "new texture(...)".
Yes, that's correct.

Quote
2.a,  If enable "defaultToKeepPixels", there will need another 256*256*4 bytes when "World.draw(...)"(if enable4bpp then will be 256*256*2 bytes).
Yes. Plus the memory needed for mip-maps, i.e. plus 128*128*4+64*64*4+32*32*4+16*16*4....you can rougly estimate the memory used on the GPU as x*y*4+(x*y*4)/2

Quote
2.b,  If disable "defaultToKeepPixels", there will need no extra memory when uploaded to gpu.
No quite. The additional memory will be used too, but it will be freed after the upload, i.e. you'll still see a peak in memory usage. However, i don't encourage you do disable that setting. Consider using the Virtualizer class instead.

Quote
How to estimate the memory-usage of both keyframe-animation and bones-animation?
Keyframe animations rougly need <number of keyframes>*<number of vertices>*12 bytes of memory. bones-animation should use much less, but i can't comment on that as i don't know much about Bones.

Quote
What's the situation when i use FrameBuffer.blit(...)?
When you want to paint 2d elements on top of your rendered scene.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #2 on: August 07, 2012, 07:20:51 am »
Thanks!

Another question: how  to estimate the memory-usage of native in jPCT-AE?

I am marred by OOM. So i tried the MAT(http://www.eclipse.org/mat/) to analyse the memory usage, but seems that it could only be used to analyse java-memory-usage.

I want to know: in jPCT-AE, when and how many native memories will be allocated by who(class.methods) for what?

A general(mainly) description about this is helpful for me, thanks!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #3 on: August 07, 2012, 07:39:53 am »
I've answered to that question in the other thread: http://www.jpct.net/forum2/index.php/topic,2898.msg21335.html#msg21335. However, i don't understand what do you think that this will give you!? It's actually pretty simple: You are using too much memory for your VM. The solution is also simple: Don't to it.
The wiki has some information about how to save memory and if that doesn't help, reduce the size of your assets starting with texture sizes. What are your texture sizes? People sometimes tend to use insane texture sizes on mobile devices...we have multiple threads dealing with that.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #4 on: August 07, 2012, 09:05:29 am »
To avoid OOM, the dvm mem limit should >= java mem usage + native mem usage

So i need to know how to estimate both java mem usage and native mem usage.

There are some tools which can report the java mem usage clearly. But i don't know how to estimate the native mem usage. As you say,  "older" vm won't report that.

To resolve OOM, what i do first is to find the component(s) which consumed the most memory, then improve it. 

In short, for my app, the java mem usage is about 11.5M(5M for mesh, 1.5M for animation, 2M for textures, 500K for VisList...). But i have no idea about the native memory usage, so i don't know which one (of mesh、animation、textures) should i decrease first, because i want to get the most benefit of memory-improvement with the least modifying. Does the mesh(Object3D) use the native memory?  Does the animation(bones) use the native memory? Dose the textures use the native memory?

And i want to add some features in my app in future, so i need to know the left mem of vm = vm limit - "java mem used "- "native mem used ".
 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #5 on: August 07, 2012, 10:14:34 am »
In short, for my app, the java mem usage is about 11.5M(5M for mesh, 1.5M for animation, 2M for textures, 500K for VisList...). But i have no idea about the native memory usage, so i don't know which one (of mesh、animation、textures) should i decrease first, because i want to get the most benefit of memory-improvement with the least modifying. Does the mesh(Object3D) use the native memory?  Does the animation(bones) use the native memory? Dose the textures use the native memory?
I've posted here multiple times about the memory usage for textures and the information can be found in the wiki too. Sorry, if i sounded a bit harsh, but i really don't want to repeat myself over and over again albeit i know that this is a problem that most people will suffer from sooner or later.

I've also already said that decreasing the texture size first is reasonable, because they usually consume the most memory (both vm and native). Bones' animations don't use native memory as far as i know. Object3Ds use native memory. I've already explained that in the other thread.

Hope this helps.
« Last Edit: August 07, 2012, 10:48:38 am by EgonOlsen »

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #6 on: August 07, 2012, 12:22:52 pm »
Thanks!

Before the previous posting, i have tried to search early threads about that in the form, but the result is not good enough for me.

I will try to search again, thanks for your patience!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #7 on: August 07, 2012, 12:30:16 pm »
Before the previous posting, i have tried to search early threads about that in the form, but the result is not good enough for me.
But i posted a formular above:

Quote
You can rougly estimate the memory used on the GPU as x*y*4+(x*y*4)/2

That's the additional native memory requirement (Edit: For textures...). Maybe i didn't make this clear enough, but that is it.
« Last Edit: August 07, 2012, 12:37:12 pm by EgonOlsen »

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #8 on: August 09, 2012, 03:03:16 pm »
Thanks! Now i got it!

I have read this formular, but i really don't know the memory usage of gpu for textures means "native memory usage" before.

And another question, i know it is not about jPCT, but i really want to get help:

Android 4.0, when my app-process spawned, there were some preload-system-resources(some drawables and other res which were loaded by Zygote, and spawned for each process),  they consumed about 4.1M of memory in my test. I don't use them at all in my app, so i want to free them, but i don't know how to do this.

I have referred the docs of google, and ask this in many forums, but seems not help.
« Last Edit: August 09, 2012, 03:21:37 pm by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #9 on: August 09, 2012, 09:33:34 pm »
Android 4.0, when my app-process spawned, there were some preload-system-resources(some drawables and other res which were loaded by Zygote, and spawned for each process),  they consumed about 4.1M of memory in my test. I don't use them at all in my app, so i want to free them, but i don't know how to do this.
What exactly do you mean? That creating an empty Activity already consumes 4mb of VM memory?

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #10 on: August 13, 2012, 08:36:35 am »
What exactly do you mean? That creating an empty Activity already consumes 4mb of VM memory?

Yes, and the 4mb of memory was consumed by androd-system-preloaded-res. 


« Last Edit: August 13, 2012, 09:01:05 am by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to estimate the memory-usage in jPCT-AE?
« Reply #11 on: August 13, 2012, 04:14:18 pm »
Strange. I've found people asking this or a similar question but no satisfying answer...