jrk@information-systems.east-anglia.ac.uk (Richard Kennaway CMP RA) (10/31/90)
According to IM, GetScrap will automatically resize the handle you give it as its first argument so as to be large enough to hold the scrap data, and behave sensibly (i.e. not crash) if it cant get the memory. However, I've found that the latter is true, but not the former. When GetScrap successfully resizes the handle I give it, I sometimes dont get the correct data in it. It's as if at some point the handle got moved, without its data being copied to the new location. This has only happened when the data was larger than 32k, though whether that's a coincidence I dont know. I've worked around this by always first calling GetScrap with a nil handle, to find out the size, then making a handle that size and passing it to a second call of GetScrap. Is this a bug? I havent seen this behaviour described anywhere. If the above work-around is necessary, then the example code in IM1 p.460 is wrong, but GetScrap isnt even indexed in IM4 or the latest index to the TNs. I'm using MPW C 3.0, if it matters. -- Richard Kennaway SYS, University of East Anglia, Norwich, U.K. Internet: jrk@sys.uea.ac.uk uucp: ...mcvax!ukc!uea-sys!jrk NB. Due to local difficulties, I'm posting by a nonstandard route. The addresses in the .sig are definitive, I dont know what the header is going to look like.
rmitchel@bbn.com (Rob Mitchell) (03/18/91)
Hi, I've set up a sequence of calls like below: Str255 pStrA, pStrB; char cStr[2000]; Handle h; int length, offset; ZeroScrap(); PutScrap (pStrA[0], 'TEXT', pStrA[1]); PutScrap (pStrB[0], 'TEXT', pStrB[1]); ... h = NewHandle (0); HLock (h); length = GetScrap (&h, 'TEXT', &offset); HUnlock (h); Length returns system error -108 (memFullErr - Not enough room in heap zone, iMemFullErr - same but from Print Mgr call). I've expanded heap, MaxApplZone, etc. Any ideas??? Rob Mitchell Advanced Simulation Division Unix & Macintosh Engineer BBN Systems & Technologies Internet: rmitchel@vax.bbn.com 33 Moulton Street MS: 8/C Primary Dwelling: 617-873-4041 Cambridge, MA 02138 Secondary Dwelling: 617-873-4071 FAX: 617-873-4315 These opinions are mine and mine only. They do not represent BBNs' opinions.
dagr@nmpcad.se (Dag Rende) (03/20/91)
You make life hard for the memory manager! The HLock/HUnlock calls must not be used here. Remove them and it will probably work. When you call GetScrap, it tries to resize the handle you supply to fit the data got from the scrap. In your case you allocate a zero length handle. GetScrap must probably grow it. As you HLock it, it must be unused space enough following the handle in the heap. That is not often the case and the memory manager gives up. With an unlocked (relocatable) handle, the memory manager can pack the heap and find a new place for your handle big enough for the scrap data.