Xref: utzoo comp.sys.mac:43740 comp.sys.mac.programmer:10991 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sunybcs!sbcs!sboslab3!vallon From: vallon@sboslab3.CS.SunySB.EDU (Justin Vallon) Newsgroups: comp.sys.mac,comp.sys.mac.programmer Subject: Re: Novice Programmer Question: Dynamic Memory Allocation under TC Message-ID: <4196@sbcs.sunysb.edu> Date: 7 Dec 89 23:47:13 GMT References: <24770@cup.portal.com> Sender: news@sbcs.sunysb.edu Reply-To: vallon@sboslab3.CS.SunySB.EDU (Justin Vallon) Distribution: usa Lines: 51 In article <24770@cup.portal.com>, David_Anthony_Guevara@cup.portal.com writes: > [Porting an application from Vax to Mac] Questions: > When you use malloc to create a > node (ex: head = (struct linked_list *) malloc (sizeof( ELEMENT ));) > does the memory allocated come from the stack or the application heap? Application heap. Otherwise, it would be deallocated when the function returns. > I believe my problem is that the Mac is relocating my pointers and the > program just drops into a black hole. Nope. Malloc calls NewPtr, which will never relocate a block of memory that it returns. See Inside Mac chapter on the Memory Manager. > No bomb, but it just sits there > until I reset the system. If the storage is allocated from the application > heap, how can I make sure that nothing gets moved while the program is > running? It wont. See above. > I'm not using any toolbox calls, should I be? No, you don't have to if you want to write a C (Object-C?) program. The Mac interface libraries make TC as close to "real" C as possible. > As I said, the > program DOES run on my VAX without any difficulty. My configuration is > a Mac Plus w/4Mb RAM, Think C 4.0, System 6.02 with assorted inits and cdevs. > Thanks for any help you can give me! Sorry that I couldn't give you any good news, but the problem must be in you program. Actually, one problem that I have a lot of times is forgetting that malloc takes a long (32-bits). ThinkC assumes an int (16-bits) if no prototype is given. See if malloc is being declared as malloc(long), or put it in yourself: Ptr malloc(long); If that doesn't help, then feel free to send me mail directly. > Dave Guevara, > Internet: guevara@fsd.arc.nasa.gov > guevara@fsdvx2.arc.nasa.gov > David_Anthony_Guevara@cup.portal.com -Justin vallon@sbcs.sunysb.edu