Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!apple!sun-barr!lll-winken!ncis.tis.llnl.gov!blackbird!pvarner From: pvarner@blackbird.afit.af.mil (Paul A. Varner) Newsgroups: comp.lang.c Subject: Re: malloc() Message-ID: <1561@blackbird.afit.af.mil> Date: 7 Apr 90 23:20:27 GMT References: <1550@blackbird.afit.af.mil> Reply-To: pvarner@blackbird.afit.af.mil (Paul A. Varner) Distribution: na Organization: Air Force Institute of Technology; WPAFB, OH Lines: 39 In article <1550@blackbird.afit.af.mil> I wrote: >To all you 'C' gurus: > I am in the process of porting some C code to be as portable as >possible across many different machines. Anyhow, one of the calls I >have to make is malloc(something), where somthing is a BIG value, such >as 300,000. Anyhow, the code works perfectly on a Unix machine I have >access to, but bombs out in Turbo C, using the huge memory model. >When I say bomb, it locks the machine up. Anyhow, I really need to >keep the Malloc call in the code. Any suggestions?? In response to this, I have received many suggestions. I appreciate all the help and thank the following people who sent me their advice. rds95@leah.Albany.EDU (Robert Seals) raymond@math.berkeley.edu (Raymond Chen) D. Richard Hipp tarvaine@jyu.fi (Tapani Tarvainen) grimlok@hubcap.clemson.edu (Mike Percy) einari@rhi.hi.is (Einar Indridason) Alvin I Rosenthal kdq@demott.com (Kevin D. Quitt) "Rich Walters" Marvin Rubenstein gordon@sneaky.lonestar.org (Gordon Burditt) G.Toal%edinburgh.ac.uk@NSFnet-Relay.AC.UK HENRIK SANDELL npw@nbsr.nbsr.duke.edu (Nicholas Wilt) s.michnowicz@trl.oz.au (Simon Michnowicz - A Free Spirit) kim@wacsvax.OZ (Kim Shearer) My problem is caused by several things. The first was that malloc is defined so that it takes parameters of size_t. On the Unix system I was using size_t is the length of a long. In Turbo C, it is the length of an int. Therefore, I was mallocing something like 300,000 mod 65536 and expecting to have all 300,000 bytes. The second was that since, I was actually allocating some memory, the malloc call was not returning NULL. The solution to this problem was to use the function farmalloc. This function takes a long as a parameter. The next thing is that in order to address all of the memory allocated I needed to cast to a huge pointer.