gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > RAM management

#151454 - cornaljoe - Tue Feb 26, 2008 10:44 pm

I'm having problems with my current project running out of RAM. I'm using PALib which manages RAM for me so I don't know where to start to fix the problem. I have compiled Lick's RAM API into the project but it's no use without knowledge on how to manage it.

If anyone can help me out here with some tips/tutorials/examples on RAM management, I would greatly appreciate it! Thanks.

#151455 - Rajveer - Tue Feb 26, 2008 10:53 pm

When you say RAM, do you actually mean VRAM? As in you're not talking about dynamic memory allocation with malloc and free right? If it's VRAM then the best thing to do is scrap PALib I'm afraid, it's memory management is terrible and I've seen many homebrew games run out of VRAM with garbled graphics after playing for a while.

If it is RAM you're running out of, it must be a large project!

#151458 - Satan2k - Wed Feb 27, 2008 2:36 am

for me, i am just getting trouble in video ram management with libnds :p

The point is : I don't know how to replace the non-existing function glDeleteTextures() (very odd when glTexImage2D() is implemented). I am currently using glResetTextures(), but it reset all textures, so it is alittle hard to sort it out. Any idea or explainations to replace that?

#151459 - kusma - Wed Feb 27, 2008 2:48 am

Satan2k wrote:

The point is : I don't know how to replace the non-existing function glDeleteTextures() (very odd when glTexImage2D() is implemented). I am currently using glResetTextures(), but it reset all textures, so it is alittle hard to sort it out. Any idea or explainations to replace that?

glDeleteTextures() require the presence of a proper memory allocator for VRAM, and is thus a lot trickier to implement. If you need something better, implement it yourself. Pool-allocators are simple to implement, and allows you to logically group your textures by their life-time.

#151461 - Satan2k - Wed Feb 27, 2008 3:29 am

Thanks for the reply ;)

I didn't mean to be mad, or angry. I was just wondering why it was not implemented. Now i got the reply :)

Yes you are right. But all my attempts to free the gl index failed :p. e.g :

i got this for the texture allocating :
Code:
int *texture = (int*)malloc(sizeof (int)); // 10 surfaces to clean


Then i tried with ONE surface; so i load a texture on it and i show the surface
Code:
   glBindTexture(GL_TEXTURE_2D, texture[0]);
   glBegin(GL_QUADS);                           // Draw A Quad
      glTexCoord2f (0.0f, 1.0f);   glVertex3f(0.0f, 0.0f, 0.0f);               // Top Left
      glTexCoord2f (1.0f, 1.0f);   glVertex3f( 1.0f, 0.0f, 0.0f);               // Top Right
      glTexCoord2f (1.0f, 0.0f);   glVertex3f( 1.0f,1.0f, 0.0f);               // Bottom Right
      glTexCoord2f (0.0f, 0.0f);   glVertex3f(0.0f,1.0f, 0.0f);               // Bottom Left
   glEnd();


Then i load another texture at the same place [0] and i render the second surface

Code:
glBindTexture(GL_TEXTURE_2D, texture[0]);
   glBegin(GL_QUADS);                           // Draw A Quad
      glTexCoord2f (0.0f, 1.0f);   glVertex3f(1.0f, 0.0f, 0.0f);               // Top Left
      glTexCoord2f (1.0f, 1.0f);   glVertex3f( 2.0f, 0.0f, 0.0f);               // Top Right
      glTexCoord2f (1.0f, 0.0f);   glVertex3f( 2.0f,1.0f, 0.0f);               // Bottom Right
      glTexCoord2f (0.0f, 0.0f);   glVertex3f(1.0f,1.0f, 0.0f);               // Bottom Left
   glEnd();


And then it works for the first FRAME, and then it is not displaying the texture because the system ran out of memory.

I tried many ways like
Code:
texture[0] = NULL;

And the result is the same.

I tried too free(texture) and it crashes the game. When i place glResetTextures, it works :S. Any idea?

#151464 - simonjhall - Wed Feb 27, 2008 8:45 am

I wrote a texture management system for Q1 and Q2 which allows you to load and delete and stream in textures at runtime - should I package it up and upload it somewhere? Would this be useful for anybody?
_________________
Big thanks to everyone who donated for Quake2

#151465 - nanou - Wed Feb 27, 2008 9:29 am

simonjhall wrote:
I wrote a texture management system for Q1 and Q2 which allows you to load and delete and stream in textures at runtime - should I package it up and upload it somewhere? Would this be useful for anybody?

I vote yes. I'll almost certainly use it at some point if you do.
_________________
- nanou

#151467 - Rajveer - Wed Feb 27, 2008 1:03 pm

simonjhall wrote:
I wrote a texture management system for Q1 and Q2 which allows you to load and delete and stream in textures at runtime - should I package it up and upload it somewhere? Would this be useful for anybody?


I think it would be useful for everybody! :D

#151478 - SiW - Wed Feb 27, 2008 5:32 pm

simonjhall wrote:
Would this be useful for anybody?


Definitely.

#151483 - silent_code - Wed Feb 27, 2008 6:54 pm

cornaljoe wrote:
I'm having problems with my current project running out ...

back on topic guys! ;^p
i think he wants to know how to use the RAM extension some cards offer!
i suggest looking at the api "documentation" on this forum.

btw: simon, that would be great and help a lot of people. you've spent so much time on q1/q2 and making these games playable is maybe more than enough to gain from your efforts, but giving away such a module, in it's pure un-id-fied (pasta anyone?) form, that whould be just wonderful.

i'm a <but some nasty synonyms for *bad* here> poet. ;^p

#151491 - simonjhall - Wed Feb 27, 2008 8:26 pm

silent_code wrote:
cornaljoe wrote:
I'm having problems with my current project running out ...

back on topic guys! ;^p
i think he wants to know how to use the RAM extension some cards offer!
i suggest looking at the api "documentation" on this forum.
Good point.
To the OP: we really need to know if it's VRAM or normal RAM that you're running out of. Since I doubt palib does garbage collection, smart pointers and reference counting and all that crap I'd imagine that it's video RAM that you're short on. If it is, what types of graphics are you doing, and how would you want to manage them in an ideal world?
_________________
Big thanks to everyone who donated for Quake2

#151497 - cornaljoe - Wed Feb 27, 2008 11:15 pm

I believe I was mistaken. I found some code that returns the amount of free RAM available. I had ~3.2MB left so maybe it's VRAM or some other problem. Is there a way to get the current amount of VRAM available?

I'm using Noda's ASLib to stream an MP3 through FAT. Everything works fine until I try to copy a file to the FAT being accessed by ASLib. Small files copy fine, but when copying larger files the copying stops and the MP3 will loop its current buffer(~1sec).

I still would like some documentation on RAM/VRAM management if I'm wrong. I searched for a few days and all I can find is source without much commentary. Thanks for the help.

#151501 - Lazy1 - Thu Feb 28, 2008 1:08 am

libfat Is not interrupt safe, if you are doing I/O in interrupts you must first disable the interrupt you are using in the main loop then read your data and re-enable the interrupt afterwards.

Code:

void main_loop( void ) {
   while ( 1 ) {
      // Read stuff
      irqDisable( irq_using_libfat );
      fread( blah, 1, 1, fp );
      irqEnable( irq_using_libfat );
   }
}


That worked for me, maybe someone else has another suggestion.

#151504 - silent_code - Thu Feb 28, 2008 1:54 am

there is no such thing as a "free vram" amount, because until you don't load anything into vram, it's all free. so you can manually "manage" it or write some manager (or wait until simon releases his vram manager / "steal" it from his q1 nds source files, which are available under some sort of license [l/gpl?]. ;^p )

#151550 - cornaljoe - Thu Feb 28, 2008 9:32 pm

Wow, I feel so stupid! I just had to put a VBL in my copy loop and that fixed it. Sorry for all the trouble.

#151747 - Rajveer - Tue Mar 04, 2008 12:30 pm

Lazy1 wrote:
libfat Is not interrupt safe, if you are doing I/O in interrupts you must first disable the interrupt you are using in the main loop then read your data and re-enable the interrupt afterwards.


Haha, after months of thinking my game was messed up somewhere I couldn't see, you've finally solved my problem, cheers! :)