Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!bionet!apple!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: HandleObject vs. 5+ meg of RAM and Virtual Memory Message-ID: <9030@goofy.Apple.COM> Date: 6 Jul 90 23:23:39 GMT References: <279@unf7.UUCP> Organization: Apple Computer, Inc. Lines: 57 In article <279@unf7.UUCP> shite@unf7.UUCP (Stephen Hite) writes: > > If I have 5 or 8 meg of RAM and virtual memory (a.k.a System 7.0.2 :-)) >is it really *worth* the limitations of using HandleObject? Some of limitations A lot depends on your application. Memory fragmentation occurs when you have a lot of allocations & deallocations or varying sizes. If you memory allocation patterns are fairly regular, then fragmentation may not be a problem. Even if you have 8Mb of RAM, you still have to think about the application partition size under MultiFinder, since that's what limits the application's available memory. Even 8Mb is still a finite amount of memory, and it isn't hard for an application to fill it all up. > 1. You can't "...declare global variables, local variables, arrays, members, > or parameters of handle-based types (rather than pointers to them)." This isn't really a limitation. What that means is that all instances of a HandleObject must be on the heap. > 3. "It is not possible to allocate an array of handle-based objects, for > example, new MyObjects[10]." Again, you can allocate an array that contain the handles, but not an array that contains the objects themselves. > 4. You cannot "...take a pointer to a field of an indirect class (i.e., > &x->y). This restriction includes the implicit use of pointers by ref- > erences, such as int& p = x->y." When I tried this out, it appears that the compiler allows you to do this. But, of course, you are dereferencing a handle, and the pointer isn't valid if the heap is compacted. C++ was designed in the UNIX environment where memory space isn't (as much of) an issue. The dispatching scheme, for example, is about as fast any scheme can be, at the cost of larger virtual tables than Object Pascal, for example. (Multiple inheritance doubles the size of the virtual tables, by the way. That's why MPW C++ also includes the SingleObject class.) The nice thing about MPW C++ is that you can mix native C++ objects with HandleObjects or Pascal objects. Other than the restrictions on the use of the objects (which aren't very onerous), you use each kind of object in the same way. In the case of HandleObjects, the basic restrictions are: (1) they must be allocated on the heap, (2) the can't use multiple inheritance, (3) they're implemented with handles which means you have to worry about heap compactions. -- Larry Rosenstein, Object Specialist Apple Computer, Inc. 20525 Mariani Ave, MS 46-B Cupertino, CA 95014 AppleLink:Rosenstein1 domain:lsr@Apple.COM UUCP:{sun,voder,nsc,decwrl}!apple!lsr