From: qball1723 AT aol DOT com (QBall1723) Newsgroups: comp.os.msdos.djgpp Subject: Re: What does/doesn't need memory allocated? Date: 9 Jan 1998 08:16:41 GMT Lines: 52 Message-ID: <19980109081601.DAA01257@ladder02.news.aol.com> NNTP-Posting-Host: ladder02.news.aol.com Organization: AOL http://www.aol.com References: <199712311919 DOT LAA08200 AT adit DOT ap DOT net> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk > >At 05:59 12/31/1997 +1030, Richard Sim wrote: >>Hi, I just spent several days trying to get a routine working because I >>forgot to allocate 5 bytes of memory, and I was wondering if there are any >>programs/documents that tell you what needs to have memory allocated to it. >>i.e. Goes through your code and finds things that need memory allocated to >>them, or a text that explains things like this... >>Just if you didn't have to allocate memory all of the time...or if there was >>something that would tell you what you have to allocate memory for and what >>you don't :-). >>Oh well, if anyone knows of anything like this could they please tell me >>since I really need it. :-) >Try compiling with `-Wall'. This may find problems with accessing >unallocated memory. >Basically, almost every time you pass a pointer to a function, the pointer >should point at something accessible. If the data is going to be changed, it >needs to not be a constant. >> >>Also, if say you allocate a structure, do you have to do a free at the end >>of your program, or will it be totally free'd anyway? I know that you >>should, but must you? >No. All memory is automatically freed when your program exits. This should >be the case on every system. > >Nate Eldredge >eldredge AT ap DOT net > > It's good practice to explicitly allocate and free memory.... int x; <= NO - you don't have to do a malloc... ; ) (this part is allegro stuff) BITMAP *boogy; boogy = create_bitmap(320x200); destroy_bitmap(boogy); Note: load_bitmap will allocate the memory for you... so you don't have to call create_bitmap first... I go with Nate - that it's not an absolute - but it sucks when things crash - allocate your memory (it might help you keep track of it better too!) Jim the loiterer (wannabe PC game/graphics developer) http://members.aol.com/qball1723/index.htm [please don't hate me because I pay too much for poor internet service!!]