Path: utzoo!attcan!uunet!samsung!brutus.cs.uiuc.edu!apple!archer!dwb From: dwb@archer.apple.com (David W. Berry) Newsgroups: comp.sys.mac.programmer Subject: Re: Think C 4.0 questions Message-ID: <6470@internal.Apple.COM> Date: 1 Feb 90 21:23:25 GMT References: <10682@bsu-cs.bsu.edu> Sender: usenet@Apple.COM Organization: Apple Computer Lines: 39 In article <10682@bsu-cs.bsu.edu> mithomas@bsu-cs.bsu.edu (Michael Thomas Niehaus) writes: >I have several questions that I hope someone out there can answer: > >1. If you declare an array in an object class definition, is it safe to > use that array in a call to, say, an FSWrite routine? I have created > a 1K buffer and when it fills up I want to call FSWrite to write the > whole chunk out. Is this safe, or do I have to copy the whole array? > (Or can I lock it down?) Remember there are two types of objects, handle based and pointer based. Pointer based objects will never move and therefore are always safe to pass to FSWrite. Handle based objects are a little trickier, in theory it may be safe. It probably isn't though, especially if FSWrite isn't in the currently executing segment. Any routine (even those not marked "Can move memory") called via glue can move memory due to a LoadSeg call. The safest bet is something like: unsigned short state = HGetState((Handle) this); HLock((Handle) this); FSWrite(......) HSetState((Handle) this, state); Of course, if these are all your objects, and your sure they are always unlocked except for short explicit times, you can just use HLock and HUnlock, but I'm a paranoid sort of guy... > >2. If you declare a superclass and then two or more subclasses, is it > possible to create an object of one subclass and assign it to an object > variable of the superclass? I would like to have an array of objects of > different types (but of similar structures). Yup, use a type cast: super = (CSuper*) new(CSubA*); See the collection type objects in TCL for more examples.