|
Memory problems with this loop |
alex glez
Member #16,757
October 2017
|
Hello again. I have a problem with the creation, loading and destruction of bitmaps. ALLEGRO_BITMAP *PRUEBA = NULL; for (w2 = 0; w2 < 1000; w2++) This is just a test, but it is very important to adapt it to my program. Thank you |
Mark Oates
Member #1,146
March 2001
|
OK, a couple things happening here. When you call al_create_bitmap you are creating a bitmap in memory. The address of that new bitmap is then assigned to PRUEBA. After that you are re-assigning to PRUEBA the value of NULL, which means that the bitmap you created with al_create_bitmap is still dangling in memory and has not been freed. After that, you are loading another bitmap with al_load_bitmap("d:\\500.png"); which 1) allocates space for a bitmap in memory and 2) initializes the values in that data to the contents in the 500.png file. Then you are freeing the bitmap from memory that was allocated when you called al_load_bitmap by calling al_destroy_bitmap(PRUEBA); (also, you can wrap your code in <code> tags </code> and it will look like below:) ALLEGRO_BITMAP *PRUEBA = NULL; ------------ for (w2 = 0; w2 < 1000; w2++) { PRUEBA = al_create_bitmap(500, 333); PRUEBA = NULL; PRUEBA = al_load_bitmap("d:\\500.png"); // 500 x 333 al_destroy_bitmap(PRUEBA); }
-- |
alex glez
Member #16,757
October 2017
|
ok thanks, I understand, here there are plenty of al_create_bipmap and PROOF = NULL. My mind still thinks of gwbasic and msx-basic .. Regards |
|