memory leak? Weirdness, slowdown...

Blitz3D Forums/Blitz3D Programming/memory leak? Weirdness, slowdown...

_33(Posted 2007) [#1]
Hi,

I've spent lots of time figuring out a good terminal system for my game. But I sort of found lately a memory leak. Seems every time I send a page clear, the framerates go down... (!) So I figured, maybe my code contains a leak. So I copy/pasted it here so I could get a visu idea of wether this is good practice coding or not.

Function clear_term_screen(page_num% = 9, chars% = 1, colors% = 1, attrs% = 1, fonts% = 1)
   If page_num = 9 Then page_num = term\current_page
   term\page[page_num]\cursor_col      = 0
   term\page[page_num]\cursor_row      = 0
   Local disp_end% = term\page[page_num]\cols * term\page[page_num]\rows - 4
   Local t_color_clear% = term\page[page_num]\cls_t_color Shl 24 + term\page[page_num]\cls_t_color Shl 16 + term\page[page_num]\cls_t_color Shl 8 + term\page[page_num]\cls_t_color
   Local b_color_clear% = term\page[page_num]\cls_b_color Shl 24 + term\page[page_num]\cls_b_color Shl 16 + term\page[page_num]\cls_b_color Shl 8 + term\page[page_num]\cls_b_color
   Local char_clear% = term\page[page_num]\cls_char Shl 24 + term\page[page_num]\cls_char Shl 16 + term\page[page_num]\cls_char Shl 8 + term\page[page_num]\cls_char
   Local attr_clear% = term\page[page_num]\cls_attr Shl 24 + term\page[page_num]\cls_attr Shl 16 + term\page[page_num]\cls_attr Shl 8 + term\page[page_num]\cls_attr
   Local font_clear% = term\page[page_num]\cls_font Shl 24 + term\page[page_num]\cls_font Shl 16 + term\page[page_num]\cls_font Shl 8 + term\page[page_num]\cls_font
   For disp% = 0 To disp_end Step 4
      If colors Then PokeInt term\page[page_num]\t_color_table, disp, t_color_clear ;text color palette id's
      If colors Then PokeInt term\page[page_num]\b_color_table, disp, b_color_clear ;background color palette id's
      If chars Then  PokeInt term\page[page_num]\text_table, disp, char_clear ;text
      If attrs Then  PokeInt term\page[page_num]\attr_table, disp, attr_clear ;character attributes
      If fonts Then  PokeInt term\page[page_num]\font_table, disp, font_clear ;font id's and sizes
   Next
End Function


These tables, are initialized as follows:
   term\page[page_num]\text_table        = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
   term\page[page_num]\t_color_table     = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
   term\page[page_num]\b_color_table     = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
   term\page[page_num]\attr_table        = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
   term\page[page_num]\font_table        = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)


Any hint appreciated.

BTW, what happens is, when I start the terminal, I get decent 750+ fps. The first clear I do (cls command in console calls this function), as all of them, will blank the page nicely. Yet, the framerates go down. Every clear page I do drops the fps by 50, up to a point where I get around 400 fps, and then it stops dropping fps! So I'm rather intrigued on how this could be possible. There are no fancy tricks as to wether I change pages, or change some pointer/size values. It's just a simple and clean bank init routine really.


jfk EO-11110(Posted 2007) [#2]
Not easy to spot. Try to isolate it further.


_33(Posted 2007) [#3]
I tought maybe it was in the usage of the bit shifting, or maybe in the PokeInt, or usage of Int defined variables with PokeInt. These can corrupt memory easily.

It could be somewhere else thoe. But I was confused and posted this here to make sure I'm not off track with the code.


Dreamora(Posted 2007) [#4]
There is another potential thing that could cause the slow down: Massive amount of data and just not enough RAM to hold it ... (or too many type instances created but without any exact numbers on that, its hard to say ...)


_33(Posted 2007) [#5]
I'm not creating more pages all the time. There are 5 layer of, say 80x60 characters (80 cols, by 60 rows). That's equal to 4800 bytes per layer, meaning 4800*5 = 24K bytes. There's say 8 pages of those, that means 24K * 8 = 192K. So, yea, if I had a Commodore 64 then I'd be in trouble, but I have 2 gigs of ram :P

It's not massive amount of data, and it's not a lot of ram usage. When I quick check the ram from the console, I still have 1.3 gigs free, plus I use TaskInfo to report the ram. It's definately not anything of that nature.

It's possible the problem is not in this particular piece of code. I'm just double checking with my fellow coders to see if I have missed something.

EDIT: OK, I found the problem. It has absolutely no relation with memory leaks or whatnot. Happy! It was another problem I have with things that don't show up on screen but take processor time, and that ti should show up. It's something else I have to fix.

Cheers.