Article View: comp.sys.mac
Article #9098Re: Novice Programmer Question: Dynamic Memory Allocation under TC
From: Justin Vallon
Date: Thu, 07 Dec 1989 23:47
Date: Thu, 07 Dec 1989 23:47
51 lines
2452 bytes
2452 bytes
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
Technical Details
Message-ID:
<4196@sbcs.sunysb.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sunybcs!sbcs!sboslab3!vallonReferences:
<24770@cup.portal.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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