Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Macintosh handles Keywords: handle, TextEdit, FSWrite Message-ID: <8043@hoptoad.uucp> Date: 18 Jul 89 22:06:07 GMT References: <1044@clinet.FI> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Distribution: comp.sys.mac.programmer Organization: Eclectic Software, San Francisco Lines: 40 In article <1044@clinet.FI> maa@clinet.FI (Miika Asunta) writes: >1) What is the best way to allocate a chain without fragmenting the > memory? Using handles is not as simple as you might think at first > - You need to allocate master pointers with MOREMASTERS for all your > handles in the main datasegment (#1), and you won't know the amount > of handles in a chain forehand. I know that when all of them are > in use system calls moremasters again to allocate more pointers, but > it can fragment memory! The recommended way to do this is to determine your master pointer requirements empirically. This is described in Tech Note #53. Briefly, exercise your program thoroughly, then break into MacsBug and count the number of master pointer blocks. These are the NON-relocatable blocks of size $108, $10c, or $110 bytes. Then add calls to MoreMasters in The initialization code in CODE 1 to create this many master pointer blocks plus 20%. It would probably also be wise to scale this number according to the amount of available memory. The Tech Note used to have a note about a dynamic master pointer allocation technique used by ResEdit that was better, which was supposed to be the subject of a future Tech Note, but this comment is no longer present in the current Tech Note #53. Presumably, it wasn't that great a technique after all. >2) How can I store a TEstylehandle entirely into a file? Is > the following (written in pseudo-code) enough: > FSWrite n bytes , pointer (TEstylehandle^) That's just about correct, yes. In C, actual code would be: FSWrite(refnum, (long)(*te)->teLength, *((*te)->hText)); and if my Pascal hasn't gotten too rusty, that would be: FSWrite(refnum, te^^.teLength, (te^^.hText)^); You can do much the same to read a small text file into a text edit buffer. -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com "Philosophy is the talk on a cereal box Religion is the smile on a dog" -- Edie Brickell, "What I Am"