![]() |
|
beginner problem |
Benjamin Hiltpolt
Member #6,733
December 2005
|
Hi all! I decided to write my first game. I have less programming experience so i think i did some beginners mistakes. the code looks like that:
Hope the code is clear to understand. Now if I start the game it draws everything allright, but the problem is that the space requirement is increasing permanently. Where do I have to free my memory or what shall i do? |
gnolam
Member #2,030
March 2002
![]() |
1) Every call to a load_ or create_ function must be matched with a corresponding destroy_ call when you're done with the resource you loaded or created. 2) You're loading all your graphics and creating your buffers within the drawing loop itself. Never do this. Load them once, at the beginning of your program, and then unload them at the end. -- |
Derezo
Member #1,666
April 2001
![]() |
It's best to use constructors for something like this. class Map { public: Map() { prebuffer = create_bitmap(maxview_x+tilesize,maxview_y+tilesize); data = load_datafile("tiles.dat"); } ~Map() { destroy_bitmap(prebuffer); unload_datafile(data); } }
[edit: my blocky coding style looks scary on these forums "He who controls the stuffing controls the Universe" |
LordHolNapul
Member #3,619
June 2003
![]() |
You should study the "Dynamic Allocation in the Heap" to understand what you are doing. Search a C++ manual that speak about "new" and "delete", or "alloc"/"malloc" and "free".... When you have understood this, proceed to read the allegro manual using the .CHM help file. Best regards. |
Benjamin Hiltpolt
Member #6,733
December 2005
|
thank you all for good and fast help! |
|