Path: chuka.playstation.co.uk!scea!peter_alau@playstation.sony.com From: Dennis Payne Newsgroups: scee.yaroze.beginners Subject: Re: A Problem with Malloc and a question about InitHeap Date: Sat, 11 Dec 1999 22:15:06 +0000 Organization: Identical Software Lines: 53 Message-ID: <3852CCEA.714FF3B2@identicalsoftware.com> References: <3851a5b1.5208772@news.playstation.co.uk> NNTP-Posting-Host: 207.60.36.52 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.01 (X11; I; Linux 2.2.5-22 i586) > void AddCamera(Camera* list) > { > while( list!= NULL ) list=list->next; > list = (Camera*) malloc( sizeof(Camera) ); > ReadCamera(list); > } The code is wrong (I think). To do the equivelent of the macro: void AddCamera(Camera** list) { while( (*list)!= NULL ) (*list)=(*list)->next; (*list) = (Camera*) malloc( sizeof(Camera) ); ReadCamera(*list); } I don't think this is what you want though. This iterates through the list but does not add the item to the list. It also destroys the pointers to the list in the process. Here's what I think you want: void AddCamera(Camera** list) { Camera *prev; if ((*list) == NULL) { (*list) = (Camera*) malloc( sizeof(Camera) ); ReadCamera(*list); } else { prev = *list; while( prev->next != NULL ) prev=prev->next; prev->next = (Camera*) malloc( sizeof(Camera) ); ReadCamera(prev->next); } } (In C++ you would pass in a "Camera *&list".) If you need an explaination of what this is doing let me know. > BTW - InitHeap seems to have no effect. Oh and one last thing how do > you reclaim the memory after you have loaded your files into video > memory or into their structures(I parse a raw binary file also). After you're done with the files simply use the memory. For example if you loaded all the graphic images then you could use InitHeap with the memory addresses of where the images were stored. (I have no experience with InitHeap so I don't know why it would be a problem.) Dennis Payne dulsi@identicalsoftware.com