Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 Apollo 5/13/85; site apollo.uucp Path: utzoo!watmath!clyde!burl!ulysses!ucbvax!decvax!wanginst!apollo!granz From: granz@apollo.uucp (David Granz) Newsgroups: net.micro.mac Subject: malloc Message-ID: <2798fa87.2e20@apollo.uucp> Date: Mon, 8-Jul-85 11:33:56 EDT Article-I.D.: apollo.2798fa87.2e20 Posted: Mon Jul 8 11:33:56 1985 Date-Received: Thu, 11-Jul-85 07:53:58 EDT Organization: Apollo Computer, Chelmsford, Mass. Lines: 41 >I just tried using the malloc() supplied with the Aztec C68K commerical >package and got unsatisfactory results. After computing the size of my >array, I called malloc(), storing the returned value in a char *. > >My program acted rather strangely, apparently refusing to store anything >in the array. On printing out the contents of the pointer variable, I >found it was something like 0xfffff7b3 (in other words, off the end of >the 512K address space). I tried using lmalloc() (the application heap >version of malloc()), but got similar results (though the numbers were >different). > >Dave Bursik/..cbosgd!db ---------------------------------------- >I've noticed exactly the same thing with Megamax C. It sure is the >pits when something as funadmental as malloc screws up. One funny thing >is that malloc works until your program grows beyond a certain size. > >You can store into malloc'ed locations by masking off the upper bits of the >returned value, but that is the kind of horrible kludge that makes hackers >run screaming into the night. Depending on how much memory you have, the >number of bits to mask changes. Also, when you try to free one of these, >the Mac is likely to crash. > >A better alternative is to use the toolbox calls and/or manage your own >storage. > >--Gordon Hamachi > You should check that you declared malloc to return a pointer type before you used it. ie: char *malloc(); If you didn't, then C assumed that malloc returned an integer (16 bits) and sign extended it for you! -- Dave Granz/ ...decvax!wanginst!apollo!granz