Path: chuka.playstation.co.uk!news From: Jo180@mdx.ac.uk (John Owens) Newsgroups: scee.yaroze.beginners Subject: A Problem with Malloc and a question about InitHeap Date: Sat, 11 Dec 1999 15:38:54 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 42 Message-ID: <3851a5b1.5208772@news.playstation.co.uk> Reply-To: Jo180@mdx.ac.uk NNTP-Posting-Host: dyn025-052.mdx.ac.uk X-Newsreader: Forte Free Agent 1.11/32.235 OK first the question. I use InitHeap like this. InitHeap((void*)FREE_MEM,0x7D000); where FREE_MEM is just the first address after I load in my TMDs and TIMS. Is this right, I want to get a Heap so I can allocate around 500 kbytes dynamically. It is just that I read somewhere that the heap is actually stored in reverse so the first address would be FREE_MEM+0x7D000. Second the bug with malloc which BTW lost me a day of time is this, This macro works: #define AddCamera(list)\ while( list!= NULL ) list=list->next;\ list = (Camera*) malloc( sizeof(Camera) );\ ReadCamera(list);\ But this function doesn't: void AddCamera(Camera* list) { while( list!= NULL ) list=list->next; list = (Camera*) malloc( sizeof(Camera) ); ReadCamera(list); } when the camera pointer I pass in is more or less a global i.e. inside a global scene structure. The reason for this seems to be that when you exit the function it deallocates the memory because the pointer reference is destroyed. AFAIK that is not how malloc is supposed to work, i.e. it should only deallocate memory when you call free. However if it is my fault, and I wouldn't be suprised as I tend to prefare c++ anyway then don't hesitate to flame me and set me straight on how I should do memory allocation on the yaroze best, for linked lists etc. 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).