I'm fast running out of memory when running my game engine, anyone have any tips on how to track where it's going?
I've started using malloc_stats but I don't really understand the output...
Tracking memory usage
-
- Insane DCEmu
- Posts: 145
- https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
- Joined: Tue May 02, 2017 3:11 pm
- Has thanked: 3 times
- Been thanked: 34 times
- lerabot
- Insane DCEmu
- Posts: 134
- Joined: Sun Nov 01, 2015 8:25 pm
- Has thanked: 2 times
- Been thanked: 19 times
Re: Tracking memory usage
Check this topic from not too long ago, there's also some good link further down.
viewtopic.php?f=29&t=104322
Just keep in mind that if you,re freeing texture of PVR related stuff you need to use pvr_mem_free().
Since you work with -lgl (right?), glDeleteTexture() will work as well.
You can use pvr_mem_available() to track your PVR memory aswell.
You might have looked into this already but that's where I had my memory issue a week ago.
viewtopic.php?f=29&t=104322
Just keep in mind that if you,re freeing texture of PVR related stuff you need to use pvr_mem_free().
Since you work with -lgl (right?), glDeleteTexture() will work as well.
You can use pvr_mem_available() to track your PVR memory aswell.
You might have looked into this already but that's where I had my memory issue a week ago.
Re: Tracking memory usage
Do you mean VRAM or RAM usage?
For VRAM it's really important that you use texture compression and palettes as much as possible, this should help: http://dcemulation.org/?title=Texture_F ... compressed
For VRAM it's really important that you use texture compression and palettes as much as possible, this should help: http://dcemulation.org/?title=Texture_F ... compressed
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
-
- Insane DCEmu
- Posts: 145
- Joined: Tue May 02, 2017 3:11 pm
- Has thanked: 3 times
- Been thanked: 34 times
Re: Tracking memory usage
I haven't got as far as filling up VRAM yet
Pretty sure it's RAM I'm running out of. My application is pretty heavy anyway (2.5M) then if I'm reading malloc_stats() right (I'm probably not!) it seems like glKosInit() eats a bunch of RAM, and then my game engine loads some mesh data and runs out... but I need to understand where all the memory is going between glKosInit and the crash.
I tried the example in your link @lerabot but I couldn't get it to compile (undefined reference to __end??). I just need a function to tell me roughly how much memory is left and then I can probably figure out what's going wrong.
Pretty sure it's RAM I'm running out of. My application is pretty heavy anyway (2.5M) then if I'm reading malloc_stats() right (I'm probably not!) it seems like glKosInit() eats a bunch of RAM, and then my game engine loads some mesh data and runs out... but I need to understand where all the memory is going between glKosInit and the crash.
I tried the example in your link @lerabot but I couldn't get it to compile (undefined reference to __end??). I just need a function to tell me roughly how much memory is left and then I can probably figure out what's going wrong.
Re: Tracking memory usage
copypaste from my framework (based on that openbor code):kazade wrote: I just need a function to tell me roughly how much memory is left and then I can probably figure out what's going wrong.
Code: Select all
/*////////////////////////////////////////////*/
#include <malloc.h>
static unsigned long systemRam = 0x00000000;
static unsigned long elfOffset = 0x00000000;
static unsigned long stackSize = 0x00000000;
extern unsigned long end;
extern unsigned long start;
#define _end end
#define _start start
void set_system_ram()
{
systemRam = 0x8d000000 - 0x8c000000;
elfOffset = 0x8c000000;
stackSize = (int)&_end - (int)&_start + ((int)&_start - elfOffset);
}
unsigned long get_system_ram()
{
return systemRam;
}
unsigned long get_free_ram()
{
struct mallinfo mi = mallinfo();
return systemRam - (mi.usmblks + stackSize);
}
void print_ram_stats()
{
float sys_ram, free_ram, used_ram;
sys_ram = (float)get_system_ram() / (float)(1024*1024);
free_ram = (float)get_free_ram() / (float)(1024*1024);
used_ram = (sys_ram - free_ram);
printf("\n---------\nRAM stats (MB):\nTotal: %.2f, Free: %.2f, Used: %.2f\n---------\n", sys_ram, free_ram, used_ram);
}
Works fine for me.
also, as I said before, don't bother using KGL, it's too much trouble than it worth it. PVR api is not that much hard to use anyway.
-
- Insane DCEmu
- Posts: 145
- Joined: Tue May 02, 2017 3:11 pm
- Has thanked: 3 times
- Been thanked: 34 times
Re: Tracking memory usage
Thanks that worked!
I do prefer using libGL as my engine is cross-platform and I can more easily test the GL1 renderer if I keep it compatible. However, it does seem that libGL uses a lot of RAM:
I'll take a look and see if I can come up with a patch to reduce the memory usage.
I do prefer using libGL as my engine is cross-platform and I can more easily test the GL1 renderer if I keep it compatible. However, it does seem that libGL uses a lot of RAM:
Code: Select all
Free RAM: 11329540 (/simulant/simulant/utils/memory.cpp:45)
pvr: enabling vertical scaling for non-VGA
OpenGL initialized (/simulant/simulant/kos_window.cpp:42)
Free RAM: 5562372 (/simulant/simulant/utils/memory.cpp:45)
Re: Tracking memory usage
KGL allocates vertex buffers into which it will write polygons before sending them off to the GPU. Maybe you want to change their size?
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream