Path: utzoo!attcan!uunet!midway!mimsy!mojo!russotto From: russotto@eng.umd.edu (Matthew T. Russotto) Newsgroups: comp.sys.mac.programmer Subject: Re: Speaking of Munger... Message-ID: <1990Jul13.142801.6843@eng.umd.edu> Date: 13 Jul 90 14:28:01 GMT References: <233@sun13.scri.fsu.edu> <42917@apple.Apple.COM> Sender: news@eng.umd.edu (The News System) Organization: College of Engineering, Maryversity of Uniland, College Park Lines: 70 In article <42917@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes: >In article <233@sun13.scri.fsu.edu> pepke@gw.scri.fsu.edu (Eric Pepke) writes: >>Speaking of Munger, it's a cute little routine, but what happens when it >>fails due to insufficient memory? >> >>I run this little test program: >> >>#include >>#include >>#include >> >>main() >>{ >> unsigned char buffer[1000]; >> Handle block; >> long beforeLength, afterLength; >> >> printf("Yahoo!\n"); >> >> block = NewHandle(0L); >> >> for (;;) >> { >> beforeLength = GetHandleSize(block); >> Munger(block, GetHandleSize(block), (unsigned char *) 0, >> 0L, buffer, (long) sizeof(buffer)); >> afterLength = GetHandleSize(block); >> >> if (beforeLength + sizeof(buffer) > afterLength || MemError()) >> { >> printf("\nSize increased from %ld to %ld\n", >> beforeLength, afterLength); >> printf("MemError() == %d\n", MemError()); >> exit(-1); >> } >> else >> { >> printf("."); >> } >> } >>} >> >>and I get >> >>Yahoo! >>........................................................................... >>..... >>........................................................................... >>..... >>........................................................................... >>..... >>....................................................................... >>Size increased from 311000 to 311000 >>MemError() == 0 >> >>So, when Munger fails due to lack of memory, you cannot tell from looking >>at MemError. In this case, at least, it left the handle unchanged. Can >>somebody who knows about the internals of Munger tell me if that is >>guaranteed to be the case, or is there a possibility that the handle will >>be corrupted in any way, such as being left larger than it was but not as >>large as is needed? > > [detailed, but, except on the 64K ROMs, incorrect explanation...Sorry Keith] The real reason your MemError() test is failing is that printf uses the memory manager, and that clears MemErr (because the calls printf makes succeed) -- Matthew T. Russotto russotto@eng.umd.edu russotto@wam.umd.edu ][, ][+, ///, ///+, //e, //c, IIGS, //c+ --- Any questions? Hey! Bush has NO LIPS!