Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!claris!outpost.UUCP!peirce From: peirce@outpost.UUCP (Michael Peirce) Newsgroups: comp.sys.mac.programmer Subject: Re: How to malloc memory VERY dynamically and not out of app heap? Message-ID: <0B010004.atj47a@outpost.UUCP> Date: 24 Mar 91 23:19:32 GMT Reply-To: peirce@outpost.UUCP Organization: Peirce Software Lines: 45 X-Mailer: uAccess - Mac Release: 1.0.3 In article <1991Mar24.172706.20807@potomac.ads.com>, jtn@potomac.ads.com (John T. Nelson) writes: > > > Here's an interesting problem. Let's say I want to write a text > editor. This editor will want to handle files that might be very > small (a couple of bytes) to perhaps several megabytes of text (big > .Hqx files). To do this, I obviously want to use malloc. Problem is > that the Mac OS mallocs (or NewPtr if you like) its space out of the > application heap whose size is apparently determined by the > application's suggested size (available from command-I in the Finder). > > Okay so far? > > Now... in order to handle those BIG files this means that I need an > app size that's extremely large (several megabytes) but that means I > cripple the application because then it won't run on smaller Macs with > perhaps only two meg of memory. If I set the app size too small then > it doesn't run on those big files. It would be nice to newPtr my > space from a "free" area whose upper limit was not fixed and tied to > the application's expectations. > > What does one do in these sort of situations or have I missed > something conceptually? I would like to be able to run an app without > telling the OS how much memory I need because I don't know how much. A couple of strategies come to mind: (1) write a smart text file handler. This would read a portion of the text into a "small" buffer and keep the rest on disk. This is how MPW does it and it can work very well if designed properly. (2) If you only need this space briefly you could ask MultiFinder for it. Of course, MultiFinder may not have it to give out if there are a number of Apps running. (3) keep everything in memory and force your users to change the App Size to handle big files - and ship AppSizer with it to make life easier for them :-) ;-) -- michael -- Michael Peirce -- outpost!peirce@claris.com -- Peirce Software -- Suite 301, 719 Hibiscus Place -- Macintosh Programming -- San Jose, California 95117 -- & Consulting -- (408) 244-6554, AppleLink: PEIRCE