jrk@sys.uea.ac.uk (Richard Kennaway) (05/24/89)
I believe this question was been thrashed out here years ago, but I didnt do any Mac programming then, and I cant find an answer in IM or the TNs. The question: As far as I can tell, TextEdit routines do no error-checking of any sort. So how do I prevent a TextEdit call from crashing if it cant get the memory it needs? I can imagine two solutions: (1) Before making such a call, see if there is enough memory to allow whatever memory allocation calls it will make (but how do I tell how much that is?) Or (2) At program startup, grab a chunk of memory big enough for any one TextEdit call, write a grow zone proc to release it when necessary, warn the user when this happens, and prevent the user from doing anything that would require memory allocation, until he has obtained more memory (e.g. by closing windows). Problem with (1): what are the memory requirements of each TextEdit call? Problem with (2): what are the maximum memory requirements of any one TextEdit call? Problem with both approaches: to obtain more memory, the user may have to do things that allocate even more memory (e.g. running SFPutFile, opening a file, etc.) How do I estimate the amount of memory I must keep in reserve for such cleaning-up activities? IM provides a list of those ToolBox routines which can cause memory allocation, but is silent on the amount of memory they may allocate. Experimenting by running the program in smaller and smaller partitions until it crashes, and then backing off from there, seems, well, ideologically unsound. But I suppose it may come to that. -- Richard Kennaway SYS, University of East Anglia, Norwich, U.K. uucp: ...mcvax!ukc!uea-sys!jrk Janet: kennaway@uk.ac.uea.sys