Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!helios.ee.lbl.gov!ux5.lbl.gov!beard From: beard@ux5.lbl.gov (Patrick C Beard) Newsgroups: comp.sys.mac.programmer Subject: Re: Multiple Inheritance for HandleObjects in C++ Message-ID: <6182@helios.ee.lbl.gov> Date: 16 Jul 90 15:24:09 GMT References: <15132@reed.UUCP> <268BA8DC.4CD4@intercon.com> <37@hite386.UUCP> Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux5.lbl.gov (Patrick C Beard) Organization: Berkeley Systems, Inc. Lines: 42 X-Local-Date: 16 Jul 90 08:24:09 PDT Here is how I use Handles and C++ objects together without fragmenting heaps. This allows full C++ style objects with single and multiple inheritance. // overloaded storage operators. Allows floating C++ objects. void* operator new(size_t size) { Handle h = NewHandleClear((long)size); if(!h || MemError() != noErr) return nil; MoveHHi(h); return (void*)*h; } operator delete(void* p) { if(p) { Handle h = RecoverHandle((Ptr)p); DisposHandle(h); } } Using these storage operators, create an object like so: MyClass **h_instance, *p_instance; p_instance = new MyClass; h_instance = RecoverHandle((Ptr)p_instance); Now, you can refer to the object henceforth using h_instance, which you can cast to a handle and perform standard locking and unlocking before and after use. For example: (**h_instance).MyMethod(); // be sure to lock if necessary! -- ------------------------------------------------------------------------------- - Patrick Beard, Macintosh Programmer (beard@lbl.gov) - - Berkeley Systems, Inc. "..............Good day!" - Paul Harvey - -------------------------------------------------------------------------------