Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!decwrl!fernwood!lia!jgro From: jgro@lia (Jeremy Grodberg) Newsgroups: comp.lang.c++ Subject: Re: Portable C++ pointer/handle or memory management Message-ID: <1990Oct14.232625.333@lia> Date: 14 Oct 90 23:26:25 GMT References: <1990Oct10.170534.1162@efi.com> Reply-To: jgro@lia.com (Jeremy Grodberg) Lines: 32 In article <1990Oct10.170534.1162@efi.com> chiu@efi.com (Chan Chiu) writes: >I am going to develope a portable software using C++. The target systems are >Mac, PC/Windows and Unix. > >One thing I found out particularly troubling is memory reference/dereference. >Mac and PC/Windows use handle (i.e. moveable heap memory) model. Unix use >pointer model. >[How should I handle this?] If you use MPW C++ on the Macintosh, it will provide for you a base class called HandleObject, which overloads *, ->, [], etc. as appropriate. The interface and implementation of this class are built into the compiler, so you can't copy them, but you can use its functionality to serve as a model for the PC version. So, in all environments, all your dynamically allocated objects (i.e. objects allocated with "new") would be descendants of HandleObject. Then for each environment, you provide the appropriate implementation of HandleObject. On the Mac, it is provided for you by MPW C++. On Unix, HandleObject is an empty class, since you want the default language behavior (pointer oriented). I don't know exactly what you would do for Windows, since I know little about that environment, but you would either use an existing memory management class or write your own. Basically, though, it is a difficult problem, because there are limits to the handle mechanisms on the Mac and PC, and to the pointer mechanism in Unix, and they are often not the same limitations, so your code must be very carefully written to avoid memory problems on all machines (unless the amount of use of new and delete is very limited in your code). -- Jeremy Grodberg "I don't feel witty today. Don't bug me." jgro@lia.com