Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!cs.umn.edu!thelake!steve From: steve@thelake.mn.org (Steve Yelvington) Newsgroups: comp.sys.atari.st.tech Subject: Re: Problem with my C program [a few general hints about malloc] Message-ID: Date: 22 Apr 91 15:38:28 GMT References: <1991Apr21.210056.5685@ccu.umanitoba.ca> <1991Apr22.014758.3846@wam.umd.edu> Organization: St. Croix Valley C and Ski Lines: 45 [In article <1991Apr22.014758.3846@wam.umd.edu>, dmb@wam.umd.edu (David M. Baggett) writes ... ] > Although this isn't what you were asking about, I think it's worth > mentioning for the benefit of others who are just starting out: > > If you want to allocate more memory than can be specified in an unsigned int, > use calloc. It takes two parameters which are multiplied together to get > the size of the requested block. To allocate 128K: > > p = calloc(128, 1024); You also can use lalloc, which works like the library malloc() function except that it requires a long argument. (Be sure to include malloc.h when calling any dynamic memory management functions.) Also, good advice is worth repeating, so... > In general it is VERY WISE to avoid using the bios Malloc and Free and > use the malloc, calloc, and free provided with your compiler of > choice. (Possible exception: Desk Accessories.) Back to the original topic of this thread: (1) Never remove a disk while a file is open. (2) Never write a program that tempts a user to do (1). I'm not quite sure why the original program was written, since the Desktop handles a virtual B drive nicely (just install it!), but if I were writing such a program: (1) I'd be sure to close the files before prompting the user to remove a disk. (2) I'd call Mediach() after the swap to force an update of the GEMdos i/o buffers and make sure the action had been performed properly. I might also read the directory to be doubly sure. Beware of Murphy. ---- Steve Yelvington, Marine on St. Croix, Minnesota, USA / steve@thelake.mn.org