Mail Archives: djgpp/1999/09/11/04:52:30
Nate Eldredge wrote:
>
> Krogg wrote:
[snip]
> > ===========begin snip from allegro docs===================
> >
> > BITMAP *bmp;
> > PALETTE pal;
> >
> > get_palette(pal);
> > bmp = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H);
> > save_bitmap("dump.pcx", bmp, pal);
> > destroy_bitmap(bmp);
> >
> > =============end snip from allegro docs===================
> >
> > Well,I am lazy so i decided to try this instead:
> >
> > save_pcx("ifs.pcx",create_sub_bitmap(screen, 0, 0, SCREEN_W,
> > SCREEN_H),pallete);
> >
> > What a shortcut!...and,it worked great!
> >
> > Is there anything wrong with doing stuff like this?
> > I mean,it worked,but is there some reason i shouldnt
> > do this kind of thing?
>
> It's a memory leak. `destroy_bitmap' frees the memory used to store the
> bitmap, and your version makes it impossible to do that (the value of
> bmp is lost, so you can't find it to destroy it). Not freeing your
> resources is considered bad programming practice. If this code can only
> happen once, or a small fixed number of times, it may not be a real
> problem, since all your memory will be freed when the program quits.
> However, if it's done repeatedly, then the program will eventually run
> out of memory and die; not a good thing.
> --
>
> Nate Eldredge
> neldredge AT hmc DOT edu
Hmmm,I was wondering about that.It is only used once and
then the program exits so it wont be a problem for this
particular program.
let me try something......Ok done....
I just added a for loop to call:
save_pcx("ifs.pcx",create_sub_bitmap(screen, 0, 0, SCREEN_W,SCREEN_H),pallete);
100 times in a row to test this out.It didnt crash..I got
32 megs ram.I aint sure if this is cause win95 is providing
plenty of virtual memory or what....
You probly know more that i do about it,but i am still
clinging on to the idea that it works really good.
Was 100 times not enough for a good test?
Be Cool,
Krogg.
--
|"""""<`.THE PRINCE ,'>"""""""""""""""""""""""""""""""""""|
| `.`/""""""\,',' my sig is too big, |
|SEE HIS ( / \ \' SEE HIS but its really cool. |
| FACE \/<> <>\/ SMILE |
| / W \ Visit my ascii art site: |
| ,'\_|||||_/`. http://www.gtcom.net/~krogg/ascii/ |
| ,',' ||| `.`. krogg DOT no DOT to DOT spam AT gtcom DOT net |
|____<,' TIME TO DIE `.>____Remove no.to.spam to reply____|
- Raw text -