Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!lavaca.uh.edu!jane!cosc10s4 From: cosc10s4@jane.uh.edu (A JETSON News User) Newsgroups: comp.sys.mac.programmer Subject: Re:Re: Think C 4.0 questions Message-ID: <5436.25c970db@jane.uh.edu> Date: 2 Feb 90 17:36:59 GMT References: <10682@bsu-cs.bsu.edu> <16455@boulder.Colorado.EDU> Organization: University of Houston Lines: 41 In article <16455@boulder.Colorado.EDU>, ewing@boulder.Colorado.EDU (EWING DAVID JAMES) writes: > 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?) > > I would declare a pointer in the class declaration and allocate it in your > initialization method and DisposPtr() it in your Dispose method. This way > you won't have to worry about locking it down. And, of course, the C syntax > for accessing the data will be the same as if it were an array. This is OK, but if you have a bunch of these objects it can lead to heap fragmentation. Or if you make the items a handle, as in CCluster, you have less fragmentation but more handles. One of the problems with implementing objects as handles is that the Memory Manager gets bogged down when you have a lot of handles. One way to help is simply to put the array directly into the object handle, as Mike is doing. You can even make the array dynamic. Declaring something like: struct CMyCluster : CCollection { /* inherits numItems instance variable */ CObject* items[]; /* declare some methods... */ } and when inserting or deleting items just manage the size explicity via SetHandleSize(), as CCluster does with its item Handle. I would only do this when efficiency is of utmost importance, since subclasses of this class can no longer add instance variables. -------------------------------- Dan Podwall CS student, University of Houston COSC10S4@jane.uh.edu --------------------------------